Answer:
Generally real estate liens are prioritized following a temporal order, from first to last. This applies to all liens except taxes. Taxes are always first and they are collected before any other lien in the event of a foreclosure.
In this case, the following priority would go to the mechanic's lien from the the general contractor (as a result from court order), then the mortgage, and finally the other creditors.