StockFish at its core uses alpha-beta pruning, as explained in this post. Alpha-beta pruning by itself always gives a correct move according to perfect play, assuming the final position evaluation heuristics are correct. However, SF uses not only alpha-beta pruning, but also many other pruning heuristics that may not be correct unlike alpha-beta pruning, but will greatly increase the final depth that the search can reach. That final depth is what SF means by "depth 35". It does not mean that SF searched every line to depth 35, because it would prune off the vast majority of lines. So if those pruning heuristics are incorrect, then SF may prune off the branch with the depth-7 forced checkmate sequence at lower final search depth.
In particular, the default setting of SF is not to find the fastest checkmate sequences alone but to find the best move in general, because it is much more computationally expensive to prove a checkmate sequence. Whenever SF says #k after a fixed-depth search (such as on Lichess analysis), as far as I can tell it does imply that it searched all the branches necessary to prove that a checkmate can be guaranteed in ≤k moves. But since SF is (wisely) designed not to search for the fastest checkmate sequence (which makes it much faster), it sometimes fails to see the optimal line because it had already checked other lines that looked more promising according to the sometimes incorrect heuristics, and those lines already yielded a successful forced checkmate.
That said, I don't know why you say it needed depth 35. Lichess analysis clearly shows that it already found the #7 in the default depth-20 search.
[Edit: With the current Lichess interface it seems that the search is limited by "search time" with default being 4 s, meaning that it is not fixed-depth. I still believe that fixed-depth SF search should yield correct conclusion for forced checkmate.]