Knowing only Apple ID and password is not sufficient , you need rest of credentials if account is set with secondary authentication in which three answers for respective questions , date of birth , rescue mail address and its own password to sign in with new Mac , initially secondary authentication is required further a trusted device iPhone is essential to get verified in the account Two-factor authentication for Apple ID - Apple Support
Get a verification code and sign in with two-factor authentication - Apple Support
Use two-factor authentication for security on your Mac, iOS devices, and iPadOS devices - Apple Support
When you sign in to your account, you see that two-factor authentication is already on if it was turned on in the past. If it’s not on, you can turn it on while setting up a new Mac .
Coming to your question - If my iMac crashes and I have to buy a new iMac, will I have access to the iCloud drive contents from the old, dead computer? The contents from dead computer can't be accessed unless it's repaired in apple authorised service centre .
The new Mac has to be set up Set up your MacBook Pro - Apple Support
Sign in with your Apple ID: Your Apple ID consists of an email address and a password. It’s the account you use for everything you do with Apple—including using the App Store, Apple TV app, Apple Books, iCloud, Messages, and more. It’s best to have your own Apple ID and not share it. If you don’t already have an Apple ID, you can create one during setup (it’s free). Sign in with the same Apple ID to use any Apple service, on any device.
Note : the old computer is dead , in case if iCloud Drive / desktops and documents box was checked in it Add your Desktop and Documents files to iCloud Drive - Apple Support
Use iCloud Drive to store documents on your Mac and iOS devices - Apple Support
Note : in new Mac the Apple ID and all account credentials are to be entered , it won't be signed only with Apple ID and password .