A general construction of internal sheaves in algebraic set theory