For practical purposes as a musician or for recording, there are three main categories:
- Low-impedance, mostly, microphones (but not all microphones). These are in the 100-1000 ohm range. For these, you want to maximize power transfer to minimize noise injection. By "matching", "low-Z to low-Z" is usually good enough: be in the right ballpark, you don't have to be on the right base. That is, use gear designed for "low impedance" and you're OK.
- Line level, electronics. These tend to be in the 5K to 20K ohm region. The important thing to remember for these devices is to not "overload" the output by plugging it into something with too low an input impedance. That just puts the electronics in regions where it's not happy. On older gear, it can burn out the line level output. Mainly, this just means, "don't plug a line level output into a low-Z (mic level) input." The other implication is when using one output to drive multiple inputs. Avoid multiple Y cables unless you know the rules. In general with typical modern line outputs you can send one output to two inputs. Maybe even 4, but avoid 8 unless you do the (relatively simple) math.
- Hi-Z, like passive guitar pickups. These tend to be in the 100's of kOhms. This is also voltage transfer, so you want the input impedance to be higher than the output impedance. A good general rule is to plug a guitar into something that's made to plug a guitar into. Generally, after that, it's a line level.
So, category 1 is special: don't mix and match. For anything with a low-Z output, use a low-Z mic preamp.
When plugging a line level output into a low-Z mic input, use a "DI" (direct input) device -- but note that there are many kinds of DI, so make sure its intended use is "impedance matching." This is what we use on stage with keyboards to send them through a mic-only snake. These devices also convert unbalanced outputs to balanced, which is important for low-level signals like mic outputs sent over a long distance. (If the line output is already balanced, it doesn't matter; the "other side" is usually ignored and that's fine.)
Don't bother plugging a low-Z mic into a line level or electric guitar input. You won't get much signal and you'll get a lot of noise.
You can plug a line output into a guitar input (for the reasons given above by @Todd-Wilcox .) This is how a guitarist with a train of FX pedals works. Each pedal has a hi-Z input, suitable for plugging an electric guitar into, and a line output, which can be plugged into a mixer's line input or the hi-Z guitar input of an amp or other pedal.
Plugging a guitar into a line input can be done but doesn't give very good results, because the input impedance needs to be quite a bit higher but is lower.
So, the general rule of thumb is, use stuff that's intended for the purpose. Usually, that's pretty obvious.
Note that some (usually inexpensive) mics are hi-Z, which probably should be treated like electric guitars.
And finally, there are variations on line inputs and outputs. They can be balanced or unbalanced. Unbalanced is generally better. They can be -10dBV or +4dBu. The latter is a higher voltage and is generally better. But you can plug any type output into any type input; you just have to adjust the level on the input accordingly. (When plugging +4dBu into -10dBV, keep it low to avoid overdriving the input. When plugging -10dBV into +4dBu, you'll need to crank it up a bit but you should be fine. In any case, use your ears. If overdriving, turn it down at that stage. If noisy, turn it up at that stage and down later in the signal chain. To learn more about this, when using multiple devices in a chain, google "gain staging.")