I too find it troubling that the Supreme Court upheld the government's position that it was a valid search.
What really bothers me about it is that I can't articulate a clear legal principle about when prima facie evidence of a crime should be thrown out for moral reasons. You could say that if you're investigating one crime then discovering another one incidentally shouldn't count, but what if the police officer had been investigating a report of illegal marijuana production and had discovered the rape in progress? Of course we'd want that to be prosecutable. We could wish that the war on drugs were over and nobody would be prosecuted for Marijuana, but I can think of other petty crimes that would substitute equally well, eg if McGacken was a petty thief or something. It's a really tricky case to me. I'm surprised nobody has examined it in a law review article.
If something is seen, it seems like it would be hard to prevent the officer from making a mental note to look into that guy later. We could grant immunity, but that could also get weird. I think just narrowly excluding the evidence uncovered in the search would still probably be an improvement, though (probably...).
I don't mean to suggest that the police officer here was unethical; it's a structural fault in the law itself.