The function of the infinitive phrase in the sentence To win a marathon is my goal is object of the verb.
It is definitely an object, and it would follow a verb if it were a normal ordering of words in the sentence (My goal is to win a marathon), and since it is not preceded by a preposition, it cannot be object of the preposition, but of a verb.