How to prevent the slats coming off the side beams of a baby's cot?
You can see that the slats have glue on the ends. It was applied sloppily and the bonds let go. Get some good wood glue (Titebond, etc.) and use a cotton swab or similar to coat the entire inside of each slat socket in the rails. Also coat the slat ends lightly. 

Assemble the railing (one or more helpers make this easier) and use rope or elastic straps to keep it together while the glue dries. Be sure that the rails are the correct distance apart to mate with other parts of the bed. 

Use a damp cloth to wipe away any glue that squeezed out. Allow 24 hours for drying and reassemble the bed. Check occasionally for more leaking glue.