A contingency is essentially an exit clause in a contract. In regards to real estate and the purchase contract, a contingency protects a party from a future unknown event.
For example, the most impactful contingency in a real estate transaction is usually the inspection contingency. This allows for a buyer to have time to investigate anything related to the property. If the buyer finds something that they feel is unacceptable, they may cancel the contract under the inspection contingency.
The same holds true of the other contingencies, appraisal, loan, sale of a home, etc. If something goes wrong related to a specific contingency and you still have not removed the contingencies, you may be allowed to cancel under that contingency.