If the top answer is outdated and the official documentation actively recommends against it, itfuture visitors should either be removed, orinformed of this in a notice shouldvisible manner, and be put updirected to the recommended alternative.
Stack Overflow is meant to be a place with accurate, correct, expert-validated information. The guidelines exist to facilitate this. The guidelines are written with the intent of making the site better. Dogmatically applying the guidelines as if they were "a law of physics" rather than "a law of society" to every single case, even when it actively harms the site, is just silly and bureaucratic. As the Zen of Python states: "practicality beats purity".
Stack Overflow should not be a site where expert reviewers contradict the official documentation for the sake of preserving some non-worthwhile goal. It would be great if we could flag and removereduce the visibility of outdated answers. But until that functionality exists outside of the existing editing system, a Wikipedia-style header allows editors to communicate that information.