Note: This post is focused on the use of "change the meaning".
The trick is that a location/event is often a purpose; your purpose is to go to that location/event. With verbs ("to wear to run"), the trick is that some words can be both verbs or nouns (e.g. run as a noun is an event of running). In these cases, both may be grammatical, but slightly change the meaning.
...
You must wear a hat for gardening ... You must wear a hat to gardening
Rewording it gets
Both "You must wear a hat for gardening" and "You must wear a hat to gardening" may be grammatical, but slightly change the meaning
I understand what it means though, the sentence above itself doesn't seem clear or natural.
I've gone through the top pages linked to Ngram Viewer and didn't find similar use.
The better version could be
Both ... may be grammatically correct, but might have some nuances in meaning.
or
Both ... may be grammatically correct, though the substitution of the preposition slightly changes the meaning
Is my understanding correct?