When to use a gerund or an infinitive after "is"?

Unfortunately, the linked answer is very vague, and not correct. It does point out correctly that gerunds are more common as subjects than infinitives. But it certainly doesn't provide any rule that works.

The British Council is right. It depends on the predicate in every case, and often both are OK.

The examples given are both correct, and illustrate a difference between infinitives and gerunds:

  • My dream is to become a doctor.
    (to become a doctor describes a punctual result, with a changed situation as an outcome)
  • My hobby is listening to music.
    (listening to music describes a generic durative activity, an experiential event)

Infinitives are more complex than gerunds, and they roughly point to different kinds of clause:

As McCawley 1998 puts it (p.126) Roughly speaking,
that-complements correspond to propositions
for-to complements [infinitives] correspond to situation types
's-ing complements [gerunds] correspond to events

This is the reason why infinitives are less common as subjects. Events are causes, and causes are old information; situations are normally results, and therefore new information. And the English sentence normally presents the old information first and the new information last. That's not a grammatical rule -- it's just the usual tendency.

And in this case, note how the sentences fare when reversed:

  • ??To become a doctor is my dream.
  • Listening to music is my hobby.

The predicate be X's dream here refers to X's personal desire for a particular situation, rather than an activity that X participates in. The opposite is true for the predicate be X's hobby, which specifies an activity, but no result. So the infinitive is uncomfortable as a subject in the first sentence -- it's result, not cause; but the gerund is fine.