Few people have sufficient funds to pay cash for a house. Most go to the bank to borrow money, sign a promissory note and agree to pay back the loan. The bank advances the money, and secures its right to repayment by recording a mortgage against the real estate. You own the real estate, but the bank physically records or files a mortgage with the local Recorder of Deeds telling the world that it is entitled to be paid. This prevents anyone from buying the house without making certain that the bank is paid first.
Mechanics liens work in much the same way.
Anyone providing labor or materials to improve real estate may be entitled to record a document against the real estate. If the debt is proven and the owner cannot pay, the real estate can be sold to pay off the liens. Unlike mortgages, however, mechanics lien foreclosure sales are still relatively rare. There is usually a construction lender or ownership partners with larger stakes in the venture that will refinance, sell or pay off the project short of a sale. It is usually necessary to tear down the existing building to construct the new one, and the new one may need extensive landscape work.