Is it illegal to mortgage your spouses' retirement?

This is their retirement, not yours. It is for retirement and so you would need to evaluate if you are considering something that will contribute to their wellbeing.