Wow, someone is actually interested in understanding hardware topics. That's new.
1. Why losing ground link between connected devices may be dangerous?
That matter turned out to be really complicated and hard to summarize reasonably shortly.
It depends on many factors, but let's narrow down the cases to two devices powered with independent isolated power supplies.
First of all, there are no perfect isolators. Isolated power supplies may still conduct via impedance in Mohm range. Totally safe to humans though. There are also a few design choices to choose from, for example some consumer power supplies connect output ground to wall socket earth pin. Many laptop chargers do that, for example.
Secondly, C1 GPIO input is high impedance indeed, but only for voltages in permitted 0V - 3.3V range. If you apply voltage from outside of that range (or any current!), input impedance is almost zero. This is actually an intended behavior of almost all chips since 1970s, designed to protect against ESD. This is done by placing two diodes on each pin, that conduct voltages lower than 0V to GND, and higher than 3.3V to internal 3.3V rail.
Given all that, if you wire two devices together using their grounds, some small current may flow through this wire, originating from not-so-perfect power supplies. Unless the resistance of the connection is small enough, two devices may be considered as having a single, common ground and nothing bad happens. Ground nets in all devices have the strongest current sinking capabilities.
Now if you remove ground connection and put only signal connection instead, that parasitic current may flow through that. Not so great, given that input pins are much more fragile.
So to summarize, you get a random current flow through a wire that ends on a high impedance GPIO input. Small random current times high impedance may yield random voltage on your input pin. Which is not bad, you'll just get nonsense input data. It is very common to get 50Hz noise this way.
In a fatal case, with exceptionally s#!t power supplies and communist era wiring in the walls (Neutral pin == ground pin), the leakage current may get higher than the capability of ESD protection diodes on C1 side.
That's the reason why I suggested 10k resistor - to limit parasitic current, if ground connection fails.
I mentioned sometime ago that exactly this reason killed many USB ports and USB debuggers in my workplace. The workaround was to unplug laptop chargers for the time of work. It is also not uncommon to have at least one battery-powered oscilloscope in the lab.
2. Ground loops are bad
For DC and low frequency signals, ground is something that you take for granted - it is connected, so it must work. With higher frequencies, strange effects come into play: it takes more current to switch voltage back and forth, and as we know, current always flows in loops. Current return paths become significant for signal integrity, and this is what ground is usually used for. For really damn high frequencies, laws of physics tend to select a current return path that is counter intuitive - not the shortest one, not the one with the lowest resistance, but the one with the lowest impedance - which happens to be right in parallel to the original signal. For this very reason fast signals are always routed against ground, or even have their own dedicated return paths - which is essentially differential signalling.
So what if the return path gets disrupted for any reason? High frequency signals may partially be attenuated, reflected back and/or turned into a radio wave. In the worst case the receiver won't understand signal anymore, and in a better case your device won't pass electromagnetic compatibility certification.
This is just an example of a universal rule everywhere where voltage changes in time. Ground is not a lump of metal with constant 0V across it, if you consider any non-DC signals.
For this reasons, if ground forms a loop (which is always strictly avoided when designing anything), it forms quite good antenna. Not only current flowing through this loop will happily radiate, it will also absorb radio background we live in, and trust me it's terrible since consumers want f**ng everything wireless these days.
Another, totally unrelated reason why ground loops are bad: because they provide unintended current paths. In your example, if you added parallel ground path from C1 to a scanner, but ending somewhere on PCB with buttons, it would cause some current to go through the original path, and some through a new one. All sorts of things may go wrong from this point onward: a ground connection from button PCB to main PCB may be too weak and fail, for example. It may introduce noise to analog scanning circuitry. Basically, nothing good may ever come out of that.
Ground loop problems are so serious it's a common practice to select a "star point" in every design process - where all grounds eventually meet without looping, only branching is permitted. Even the whole spacecraft has a single star point.
I created a ground loop in my apartment some 10 years ago. I had a PC, its ground was connected to earth pin. I had a video projector on the other corner of the room, its ground also connected to earth pin. Then I used 15m VGA cable to connect them both. The ground loop was almost 30m long and had a few square meters of area. Picture was so bad it was not possible to navigate GUI. I solved the problem completely by removing earth pin connection from the projector (Please don't do that).
I can't tell which effect was stronger in this ground loop case. Either a huge antenna captured all sorts of space radiation garbage and presented it on my screen. Or, the fact that I provided an alternative path from one wall socket to the other, and added that noise to my RGB signals.
That is the reason why most audio gear has Class II power supplies - you can tell because their plugs don't make connection to earth pin. Analog signals are of course far more susceptible to ground loop problems.
The same reason why Ethernet is always isolated on every end of a cable. Imagine what would happen if it wasn't!
First time I heard about the problem was at the lecture, of course. I asked professor why won't we just add a capacitor to filter it out? I'm really glad I asked.
- It takes space and costs money
- It reduces rate of voltage change, and if it gets too slow, digital inputs without hysteresis ("non-Schmitt") may register digital noise on their own,
- Low pass filters introduce delay, and that might be unacceptable in certain cases, such as musical instruments.
So, yeah, do it in software.
4. Driving external stuff
I have an audio amp connected to 24V, and my stack of SBCs running off 5V. I wanted to automatically turn off audio amp using a dedicated pin on the board. So I did the direct connection and it worked, but added constant electronic buzz to my speakers - I could have heard RasPi's power supply noise all the time.
This is a prime example how ground loop is causing trouble not by picking up external noise, but by introducing unintentional current paths where not appropriate.
way to achieve the same goal is what prompted me to design one feature of PiStackMon. It has four optically isolated outputs, that can short something together or not, without any galvanic connection. I use this feature to pull "enable" pin low on audio amp and it works great.
So next time grab PiStackMon for controlling external stuff.