I am not sure when to is a preposition, in these two sentences below to works on the same way for me, however, avoid is not in gerund.
Use good judgment to avoid..
It was critical to achieving good returns.
Why in the first sentence to is not a preposition?