I 've given it some thought and it makes sense to me now.
Let's take things in order: You play Scheme, then Hermit. You don't buy anything this turn. In clean-up, you select Hermit with Scheme's ability. Hermit is now discarded from play. Because you didn't buy anything, it attempts to get trashed, but fails because Scheme puts it on top of deck. Then, proceeding to the next part of the Hermit's ability, you gain a Madman.
That's it i think. It's part of the genral rule "perform as much as of what the Card says as you can". In this case, you are unable to trash Hermit, because Scheme puts it on top of deck, but this doesn't cause you not to gain a Madman. If that was to happen, Hermit should be worded like this: "...When you discard this from play, if you didn't buy anything this turn, trash it. If you do, gain a Madman from the Madman pile."