"good" can have objective/rational or subjective/emotional meaning, and that it's only when used with subjective/emotional meaning that this structure has a good chance of working.
I completely agree, David. That explains why (1a) requires an infinitive and (5) allows for the more informal gerund. While in (1a) "good" is synonymous with "wise" or "advisable" (definitely more rational, objective adjectives), in (5) "good" is more like "great" (more emotional or subjective, so much so that we can also say: It feels good staying here.)
1a) It is good to take these medications.
5) It is good staying here.
c) It is pleasant for him drinking a can of beer after a long day's work.
d) It is dangerous for him swimming in the river.
e) It is a dangerous thing swimming in the river.
f) It is a pleasant thing drinking a can of beer after a long day's work.
To me, (c) and (d) sound wrong because "for him" calls for an infinitive:
c1) It is pleasant for him to drink...
d1) It is dangerous for him to swim...
I'm not sure that (e) is wrong. It might be less acceptable, as David suggested in one of his posts above, but not wrong.
I agree with you that (f) sounds fine. The presence of "thing" does not seem to interfere with the emotional "pleasant" being attributed to the gerund "drinking."