Should I get an NIE before I start applying for mortgages?

It's sensible, but not mandatory, to get an NIE before applying

The NIE (Número de identidad de extranjero or "Foreigner Identity Number") is a tax identification number in Spain.

Some banks require an NIE before giving an AIP (Agreement in Principle).

If you are serious about buying a property in Spain, then it is recommended to start your NIE application as soon as possible.