Assuming that the doors fitted correctly in the forst case, tighten the screws on the top hinges. If the screws won't tighten properly, unscrew them one by one and glue (PVA) matchsticks or timber slivers into the screw holes and then replace the screws. The problem could be in either or both the casing/lining or the door, so check both sides of the hinge
There are a couple of techniques, but they are not for the faint of heart!
1. (Leaves hinge intact) Take the door off. Drill the centre of the screw out with something like an 8mm or 9mm HSS twist drill. This needs to be done at slow speed not at 3000rpm and you should only remove enough metal so that you can pry the hinge leaf off , leaving a small bit of the.screw sticking out from the door. This can generally be unscrewed using a pair of radio pliers - in the event that it cannot it will be necessary to chisel around the screw shank with a 4 to 6mm chisel and dig it out. This rough hole is then redrilled (25 to 40mm deep) to take a hardwood dowel (get the dowel and matching drill bit before doing this - 8mm or 10mm should work) which gets coated with PVA glue and knocked in. Once the glue has set the dowel.is cut off flush with a sharp, largish chisel. When the door is rehung a new pilot hole will be required for this screw
2. (Faster but destroys hinge) cut a slot in the top of the offending screw using a Dremel and a grinding wheel. The screw can then be undone with a slotted hand screwdriver (NOT a power tool)
3. (Combination of the above). Drill the screw head out, remove hinge, grind slot as in #2 above, unscrew
And if your screws are knackered, replace them. This is especially necessary with stainless screws which really don't stand up well to being power driven with a powerful impact driver - a combi drill with the torque set lowish or even a hand screwdriver is far safer (same goes for brass screws)