Why does the order in which I put my guitar/bass pedals matter?
For example, why does the compressor needs to be the first one in the order?
This is a complicated subject. The answer depends on which effects pedals you are using. The best way to learn the results of putting your pedals in a different order is simply to plug them together in different configurations and listen to the results.
For example, a compressor works best if it is first, because a compressor works best if it receives a completely clean guitar signal that has not been changed by other effects. If you were to run your guitar into a digital delay first, making a large amount of echo sounds, the compressor would not be able to compress the echo-inflected signal effectively and the sound would be very unnatural.
You would also probably not want to use a modulation effect (reverb, echo, flanger, phase shifter) first and then send that signal to a distortion pedal. All of the crisp echoes and tonal changes in the sound (from a flanger or phase shifter, for example) would be smeared together by the distortion pedal, creating a muddy and indistinct sound. You would probably want the distortion pedal to be first, and then to send the distorted sound to the modulation effect.
Again, if you have several separate effects pedals, you should simply experiment with different orders of pedals and let your ear be the judge.
Some pedals such a fuzz pedals or wahs are very temperamental about the order in which they're placed. Typically, these two types of pedals like to see the signal straight from the guitar, before other pedals and especially before any buffered pedals. It's an impedance thing, although you'll have to Google the specifics about that.
Long story short, a fuzz after another pedal usually sounds like crap when compared to when it's first in the chain.
The short answer is yes, it matters. How much it matters, and whether it matters to you, depends on your pedals, the combinations in which you use them, and your desired sound.
Here are some general rules that most people follow; nothing's hard and fast:
Now, given all that, you are free to follow absolutely none of it. The number one rule is "experiment"; you will get different sounds by putting different pedals in different places, and what you want may not be what the next guy wants. If you want your sound to decay from a mild break-up back to clean, but a relatively constant volume level throughout instead of a volume dropoff, then by all means put your compressor after your overdrive pedal. If you want to emulate an overdriven Fender Twin Reverb, then you should definitely put your reverb before your overdrive pedal. If you want angry, sharp, dirty nu-metal grind, then put the EQ last so you can further scoop your distortion pedal's output. A looper can go almost anywhere; it depends on whether you want the looped signal to always have the effects that were on when you recorded the loop track, or if you want to be able to switch the looped sound from clean to dirty. Anything goes; you won't kill any pedal by putting anything else before or after it. What matters is your sound and how you want to get it.
Pedals often have a different effect depending on the pitch and volume etc. of the sound going into them. If a pedal changes one of these attributes of the sound, it means the behaviour of every pedal after it could be changed.
Let's say you're only using an autowah pedal. It will respond to the volume of the signal, giving loud notes/chords quite a different shape and tone from quiet ones.
If you put a compressor on after it, the autowah pedal still affects the tone and shape of the sound in the same way. The only difference is that the dynamic range (i.e. volume differences) of the final output are reduced.
If you swap the pedals over so the compressor is first, you're altering the dynamic range going into the autowah. That means it won't vary the tone as much between the loud and quiet bits, so the overall effect is reduced. That may or may not be desirable, depending on what you want to achieve.
Volume is just one example, but it isn't the only consideration. It's often a question of just experimenting with effect orders to see what gives you the best overall sound.