Before they decide on the terms of your mortgage loan (which they base on their risk), lenders must know two things about you: your ability to repay the loan, and your willingness to pay back the loan. To assess your ability to repay, they look at your debt-to-income ratio. To assess how willing you are to repay, they use your credit score.
Fair Isaac and Company built the first FICO score to help lenders assess creditworthiness. You can learn more on FICO here.
Your credit score comes from your history of repayment. They don't take into account income, savings, down payment amount, or demographic factors like gender, ethnicity, national origin or marital status. Fair Isaac invented FICO specifically to exclude demographic factors. "Profiling" was as bad a word when these scores were invented as it is in the present day. Credit scoring was invented as a way to take into account solely that which was relevant to a borrower's willingness to pay back the lender.
Your current debt level, past late payments, length of your credit history, and a few other factors are considered. Your score results from both positive and negative information in your credit report. Late payments lower your score, but consistently making future payments on time will improve your score.
For the agencies to calculate a credit score, borrowers must have an active credit account with at least six months of payment history. This history ensures that there is enough information in your credit to build a score. Some people don't have a long enough credit history to get a credit score. They should build up credit history before they apply.