סִימָן קצ – הִלְכוֹת [מַעֲקֶה] שְמִירַת הַגּוּף וּבַל תַּשְחִית
190: Laws of [Railings,] Personal Care, and Not Wasting
There is a positive obligation to make a railing for his roof, as it says “[When you build a new house], you will make a railing for your roof [and you will not place blood in your house if someone were to fall from it.]” (Devarim 22:8). The height of the railing can not be less than 10 tefachim [31.4"-37.7"] and must be strong enough that someone can rest against it and not fall.
Our roofs, which people do not use, are exempted.
However, not only the roof alone requires a railing, but also any thing which has a danger that someone can trip-up on and die, requires a railing and fixing. Anyone who leaves it wirhout a railing, ignored an obligation and violated a prohibition, as it says “and you will not place blood in your house.” (ibid) For example, someone who has a pit in his yeard, he is obligated to make a ring for it 10 tefachim high or to make a cover for it so that no one would fall into it.
The law of ma’aqeh, railings, is not actually about being safe. The word “gagekh — your roof” is taken to exclude shuls and batei medrash. Which would make little sense if the point were safety, as they equally need to be safe. As communal areas, we would actually need to be more careful.
Rather, “do not stand by your friend’s blood” would be sufficient to obligate such railings in cases where there is a real danger. Here the issue is to inculcate a culture of safety in the property owner, tooturn even cases where the danger is negligable into a mussar exercise in caring for others’ safety. This is why the obligation depends on the existence of a private owner (or owners — partnerships are also obligated).
The entire message of the mitzvah is encoded in a single letter of the verse “לְגַגֶּ֑ךָ — your roof”.