Is printing a PLA box for electronic components safe?
A printed PLA box is not very safe.
There are two main things you want from a plastic box containing mains electronics:

If the mains circuit has a fault, and starts a small fire, the case should contain that fire until it burns out, or a fuse goes.  PLA is flammable, so not only will it not contain the fire, it will feed it.
Protect people from electric shocks. E.g., if someone drops the device, cracks the case, doesn't realise, plugs it in, then gets a shock through the crack.  Or if it's plugged in and working, then someone tips over, lands on the case, breaks it open, and gets a shock.  A 3D printed case is unlikely to be strong enough unless it is very thick.

You should look for a case which solves these two problems. Both 3D printed plastics and injection moulded plastic cases can have flammability ratings, UL94 V-0 would be a good one to look for.  For physical strength I'd look for a case which I could step on without breaking it, though it might depend how the finished thing would be used (less of a worry if it's mounted on the ceiling for example).  You are likely to find injection moulded ABS cases which do what you need cheaper than 3D printing one.
Another option would be to use a metal case, in which case you should look for something similarly strong, and you should attach the metal case to the ground wire in the AC supply, preferably with something which won't work loose over time (like a crimp ring terminal + M4 bolt + lock washer).