If someone had AIDS and died of pneumocystis pneumonia, the latter is the cause of death, and the former is the cause of the latter.
Because that is what is happening when you take an extremely sick person who finally died and slap a "death by covid-19" label on them.
When influenza deaths are estimated each year, the models assume that a lot of people will die due to the virus but the cause will be recorded as heart failure or pneumonia without etiology. From the perspective of the epidemiologist, they are influenza deaths, even if they were old and frail with bad hearts.