You don’t need any formal relationship with a loanee to be named as their guarantor. However, it’s only recommended you agree to do this for people you trust and care about. You can’t be a guarantor for anyone you jointly share financial products with (eg a joint mortgage or joint bank account).
Lenders will run a credit check on you to ensure you are financially equipped to be a guarantor. This credit check will cause a short-term hit to your credit score.
If you’re not considered creditworthy enough to be someone’s guarantor, it’s likely you won’t be approved for your own mortgage either.