In the following sentence, why has it used in a -ing having form? In general, when should we use gerund or infinitive after preposition of "to"?
Like Hercules, he devotes his life to making the world a safer place.
in this case, "to" is used as a part of a phrasal verb or verb + preposition combination. One popular example of this usage is below:
I look forward to meeting your parents tonight
check this below link for other cases where you should use "verb+ing" after "to"
Here, making the world a safer place is a gerund phrase, and the to is purely as a preposition, not as an indicator of infinitive. Just like you might say to your spouse "I devote my life to you". Hercules, and the subject of this sentence, devote their life to the act or idea, or pursuit, of making the world a safer place.