ChainLocks were originally created by the developers of the Dash blockchain as a way to improve the security of a Proof-of-Work blockchain that has masternodes. Typically miners of a blockchain agree which block is next based on the longest chain rule, i.e. whichever chain is longest wins. This opens the possibility of the chain being 51% attacked, which is an attack where malicious miners with enough computing power can mine a chain longer than the honest miners can. This can then enable the malicious miners to re-organize the chain and allow them to do things such as double-spending (spending the same money more than once).
ChainLocks supersede the longest chain rule in order to provide security from 51% attacks. Long Living Masternode Quorums (LLMQs) are created, which are quorums of hundreds of masternodes that come to a decision on the next block by sharing with the other masternodes in the quorum which block they saw first. If enough masternodes in the quorum agree on the block then this process is repeated three more times (four in total) in quorums of different masternodes, if three out of the four quorums agree then this block is considered the valid next block, even if a longer chain exists. Not only does this eliminate the risk of 51% attacks but it also means that when a transaction has been confirmed once it can be considered final as chain re-organizations are negated by the ChainLocks.