The Mishna Berura (Rav Yisrael Meir Kagan of Radin, 1839-1933) addresses (in 328:38) the case of a young child who gets locked in a room on Shabbat, and he rules that in such a case one may break the door in order to let the child out. Even if this would result in creating pieces of wood that could be used as firewood, in which case breaking the door is a constructive activity and could thus constitute a Biblical Shabbat violation, nevertheless, this is allowed. The Mishna Berura explains that when a very young child is frightened, this is a potentially life-threatening situation, given the possibility of the child hurting himself in his state of panic. An older child can be convinced to remain in the room until after Shabbat, and is not likely to react in a dangerous manner, but in the case of a young child, this is considered a dangerous situation that warrants violating Shabbat.
A modern-day application of this Halacha is the case of a child stuck in an elevator on Shabbat. Hacham Ovadia Yosef (Yalkut Yosef – Shabbat, vol. 4) rules that one may call the fire department in such a case, given the potential risk this situation poses to the child.
Rav Moshe Ha’levi (Israel, 1961-2000), in his Menuhat Ahaba (21:19), applies this Halacha also in the case of a young child who is lost and wandering about in fear through the streets. This, too, is a potentially dangerous situation, and therefore one should immediately call the authorities to help this child and bring him to his parents, given the potential danger to the child’s life.
Summary: If a young child is locked in a room on Shabbat, one may break down the door if this is necessary to let him out, as this is a potentially dangerous situation. Likewise, if a child is stuck in an elevator on Shabbat, the fire department should be called in order to rescue him, and if a young child is wandering the streets lost on Shabbat, the authorities must immediately be summoned, given the potential danger.