Banks got ton of new deposits in 2020/2021 from the stimulus that went out, and they had to invest them somewhere.
Mostly they went into assets with little/no credit risk but that had duration risk (e.g. Treasuries, mortgages).
And then the Fed sucked liquidity out.