Arduino with L298N Motor Driver and external Power
You are correct in identifying that a ground loop like this is a potential safety issue. The way to avoid it is to either make sure that both grounds are at the same potential, or to isolate the ground points, whether in one or both of the power supplies or in the intermediate connection itself.

Measuring the ground potential difference is not difficult, but has its own safety issues. If measuring two mains ground potentials at the outlets, a CAT II or better digital multimeter with at least 600V of protection should be used. The measurement taken between the two ground points must be either 0V (same potential) or floating (isolated), and both AC and DC voltages should be checked.

To verify if a three-pronged power supply is isolated, measure the resistance between the power supply return and the mains ground pin. If it is less than about 100ohms after a few seconds then the supply is non-isolated. This is of course not necessarily a problem in and of itself, only when you combine it with other non-isolated devices at a different ground potential.