Although mandatory, compulsory and obligatory have three different original meanings, they are often mixed without any confusion or change of meaning. In short, it is just a matter of correctness, and also a matter of remembering which associations they normally have. However, let’s explore their original meanings:

Mandatory comes from the word mandate, which refers to an official command, or the authority given by the electorate for a government to act on their behalf. Mandatory also means essential, needed or required for some task.

Compulsory comes from the word compulsion, which means a feeling which is difficult to resist. In psychology, a compulsion is an strong irrational desire to do something, often repetitively.

Obligatory comes from obligation, which is something you have to do because it is part of your official position, or as a result of a law, or from a sense of duty or honour.

Now then, roots aside, how are they normally used?

Mandatory – usually because of a national law:
Most countries impose mandatory annual vehicle safety and emissions tests.
In some countries, the death sentence is mandatory for drug smuggling.
It is mandatory for motorcyclists to wear helmets in the EU.
Some companies make it mandatory for new employees to undergo a drugs test.
It is mandatory for young Finnish men to perform either military or civilian service, unless medically unfit.

Compulsory – usually from regulations and rules:
Compulsory education of children between about 6 and 16 years is a feature of most modern societies.
Arthur Dent’s house was in the way of the planned bypass and was the subject of a compulsory purchase and demolition order.
The wearing of a school uniform was compulsory at my old school.
The exams included six compulsory subjects and three optional ones, which could be chosen by the students.
The wearing of seat belts is compulsory now in most developed countries.

Obligatory – usually from moral, family or fashion pressure:
Many action movies contain the obligatory romantic scene, whether it is relevant or not.
It is obligatory for a gentleman to keep his word and settle his debts.
Henry found the obligatory Sunday lunch visit to his in-laws made him look forward to Monday morning.

For diplomats, evening events with important guests are obligatory.
Golf often involves obligatory and strange clothes.

Lastly – if in doubt use compulsory.