As if harassed by an enemy in the form of lusty desires, Lord Śiva followed the path of Lord Viṣṇu, who acts very wonderfully and who had taken the form of Mohinī.
Lord Śiva cannot be victimized by māyā. Therefore it is to be understood that Lord Śiva was being thus harassed by Lord Viṣṇu’s internal potency. Lord Viṣṇu can perform many wonderful activities through His various potencies.
svābhāvikī jñāna-bala-kriyā ca
(Śvetāśvatara Upaniṣad 6.8)
The Supreme Lord has various potencies, by which He can act very efficiently. To do anything expertly, He doesn’t even need to contemplate. Since Lord Śiva was being harassed by the woman, it is to be understood that this was being done not by a woman but by Lord Viṣṇu Himself.