Shaytan captures hearts when it is far from the one who created them, with no or little faith:
34:20
Sahih International
And Iblees had already confirmed through them his assumption, so they followed him, except for a party of believers.
34:21
Sahih International
And he had over them no authority except [it was decreed] that We might make evident who believes in the Hereafter from who is thereof in doubt. And your Lord, over all things, is Guardian.