The iMac you buy in 2023 is the EXACT same computer as the one you would have bought in 2021. There is NO difference. Production date doesn't matter because these things are exactly the same.
And no, since there was no 2018 iMac, you wouldn't be able to run Sonoma, even if you bought an iMac in 2018.
You are trying very hard not to understand how basic design and production in the corporate world works. If Apple had to update their iMac every 6 months to suit your thinking, the price would be twice as high, since they would have to change components and production lines again and again.