Here's how it functions:
* Gerund as a Noun: The gerund "scratching" acts as the object of the preposition "from". It's the thing that you are being prevented from doing.
* Subject of Infinitive: "Scratching" is also the subject of the infinitive phrase "to scratch that itchy spot".
In summary, the gerund "scratching" is the action you are unable to stop yourself from performing.