Are derailluers always or usually compatible with any cassettes? Is it OK to choose a derailleur without taking into consideration the cassette that will be used with it and vice-versa?
No.

It's best, though not always entirely necessary, that the number of speeds match. There are some cross-compatible options, but if you're unsure it's better to just stick with a derailleur and cassette that were designed to work together. 

It's also important to consider the size of the cassette in comparison to the amount of chain slack that the derailleur is capable of taking up. A road derailleur will often not work with a mountain bike cassette because it can not take up enough slack to account for the size of a mountain bike cassette.

Generally speaking, a cassette and derailleur that are the same number of speeds, made for the same type of bike, and made by the same manufacturer will be just fine.