I am not sure how much consensus there is around it but this is so cool I have to repeat it sorry: Whales and elephants do develop cancers but since those cancers also have mutations, well their cancers have cancers and overall the cancers are never able to grow big enough to threaten the whole organism.
Too big to fail basically
The idea that tumors develop their own tumors, suppressing cancer is known as the Hypertumor Hypothesis and, while it works in computer models, there isn't actually any evidence backing it up.
The hypothesis doesn't really resolve Peto's paradox, the observation that cancer rates don't scale directly with the number of cells in an organism. Not only do large organisms like whales get fewer cancers per cell division, small animals like mice get more cancers per cell division, which can not really be explained by a threshold beyond which hypertumors suppress tumors. The actual evidence suggests organisms just evolve whatever level of cancer resistance they need to have low odds of dying of cancer before something else kills them.
That being said, the main observation underpinning Peto's paradox was actually just due to lack of good data. Over the years much more data has been collected from animal autopsies and it turns out that big animals do get cancer and cancer rates actually do scale with body size, just different species have varying levels of cancer protection, with the levels of protection being similar in closely related species of different sizes.