The rate for a given term is based on the market's expectation of short-term rates in the future. A bank will set the interest rate it pays based on the rates that it can earn on loans of similar amounts. They generally want to get more in loan interest than they pay in deposit interest (not withstanding teaser rates and loss-leaders).
What explains the lower rate as the term gets longer?
Interest rates right now are high compared to what they were for the last several years. Without going too much into the complexities of interest rate term structures, basically the market thinks that rates will stay high in the near term but go down in the long run. If the bank offered higher rates on long-term debt, it will probably be paying a higher rate in the future than it could make on its loans.
Banks must also compete against other banks for your deposits, so there's incentives to pay higher rates, but no so high that they lock themselves in to a rate that's higher than what they'll earn in loan interest. With shorter-term CDs they can take a little more risk since the lock period is shorter.
Loans are different - the rate for loans generally goes up as the term gets longer, mostly because the bank would have a hard time selling shorter term loan at higher rates when you could just set up a loan with a longer term and pay it off early. Plus the risk of default is higher at time goes on, so they charge higher rates for taking on extra risk with a longer loan.