Books are written
A great question with a long, complex answer. The short answer is something initiates it, often an injury, either occurring spontaneously or externally.
This releases proteins that attract cells: platelets
which adhere and aggregate. They in turn release active substances that begin a cascade of proteins that form fibrin which criss-crosses forming the clot.