Answer: The Shulchan Aruch (OC 313:6; 341:1) writes that the Torah prohibition of binyan, building, does not apply to keilim, movable items, unless the connections are particularly robust. Thus, a cup that comes apart can be dismantled and reassembled on Shabbos. The Taz (313:7) and Magen Avraham (313:12) add that there is no issur of boneh to open and close something that is designed to be regularly opened and closed.
R’ Moshe Stern (Baer Moshe 6:25) and R’ Benzion Abba Shaul (Ohr Letzion 2:42:5) write that while adults should avoid playing with Lego, there is no specific prohibition in it and children can even build a model that will last some time.
Many acharonim including the Chasam Sofer (OC 72) write that temporary building does not constitute binyan. Following this, R’ Ovadia Yosef (Yabia Omer OC 7:39; Yechave Daas 2:55) writes that one should be able to play with Lego on Shabbos, especially if one is playing rather than building a specific model to last. He notes that R’ Shlomo Zalman Auerbach (quoted in Shemiras Shabbos Kehilchasa 16:19: n57) initially permitted playing with Lego though later questioned it. Nonetheless, R’ Ovadia concludes that one may play with Lego.
Similarly, R’ Eliezer Waldenberg (Tzitz Eliezer 13:30-31) answers R’ Auerbach’s challenges and writes that there is no prohibition in playing with Lego on Shabbos.
R’ Pesach Eliyahu Falk (Machazeh Eliyahu 1:69) writes that while joining two pieces together is permissible, one shouldn’t even allow one’s children to play with Lego on Shabbos because building models could come under the prohibition of kesiva, and building a house with a roof could be creating an ohel.
In conclusion, one does not need to prevent children from playing with Lego on Shabbos, though it is preferable if they don’t build complete models or buildings.