tl;dr Bond prices and rates have an inverse relationship. When bond prices go up, their yield goes down. Mortgage rates are roughly based on bond yield—specifically the 10 year Treasury.
Bonds are issued with all the details cast in stone: amount, interest rate, payment dates, repayment dates, any caveats, etc. Unfortunately the economic data of the world is not, so in the future rates may be higher or lower. If future rates are lower, can you see how a bond with higher rates would be more valuable? People would want it (demand) which would make the price rise until the effective yield (interest rate payment, or ‘coupon,’ divided by the new price) was about equal to the current yield. Of course if rates increase, the opposite has to happen: bond prices have to drop until yields get high enough to be competitive. Don’t forget you’ll lose any overpayment or get any underpayment when the bond matures! The par value, or the value of the bond when issued, will be the same amount repaid regardless of what you paid for it later (most calculators do this math for you, just be aware of it!).
What else impacts bond prices? Credit. Will the issuer, the company who originally sold the bond, be able to afford to pay it back? What if you’re in year 8 of a 10 year note and suddenly a lawsuit makes it seem the issuer will be bankrupted? On the other hand, the American federal government has a pretty good track record of paying their bond principal at maturity.
What’s all this have to do with mortgages? Well if you want to borrow money for a mortgage, you have to compete with the rest of the credit industry. If the 10 year Treasury note is yielding 1.5%, and it costs about 1.5% to write a specific type of mortgage, you can see that mortgage should cost about 3%. What if your credit is better than average? Maybe 2.75. Worse? 3.50 or even higher.
The more people buy 10 year T-notes, the more the yield drops, and the cheaper mortgages get. The stock market soars, and competing notes get more expensive, along with mortgages.