This one is not as straightforward as it seems, but there is a contradiction in there nonetheless. Bear with me. At face value the contradiction appears to be as follows: The devil can capture anyone at will/The devil will run away from those who resist him. But the contradiction is a little more subtle than that. Let’s first put these verses into context.
In 2 Timothy 2:26 Paul is in the middle of his crusade to spread Christianity. He comes across many non-Christians, who have no interest in his mission. Paul blames their stubbornness on being held captive by the devil, who blinds them to truth. Here, it’s implied that the devil can take them at will because they had never heard the gospels of Jesus.
In James 4:7, on the other hand, James is talking to Christians, who have already heard and accepted the gospels. The devil’s will to capture them is weak, so long as the Christians continue to resist him.
So in context, this appears to be not a contradiction. Sometimes, however, putting things into context exposes its weakness. It is generally accepted in Christianity that sin is the product of the devil, and (even leaving original sin to the side) it’s impossible to live sin free. James goes on and on about the sinfulness of Christians. So it should be accepted that when Christians resist but still commit sin, the devil is not fleeing from them. This would put Christians and non-Christians on the same level: the devil indeed tempts them to sin and doesn’t run away.
We can strike out the devil fleeing part from James, because obviously that’s not true.* That leaves us strictly with the question about the devil’s will to capture us. It can also be assumed that the devil successfully captures us by his own will when we commit sin. In 2 Timothy, Paul leads us to believe that it’s possible to free oneself from the clutches of the devil (even when he has captured us by will). Therefore, the answer is that the devil can capture us at will, but we may free ourselves from his clutches. James is merely a false contradiction.
*Don’t worry, none of it’s true. The devil doesn’t exist.
It would be better to believe that the devil doesn’t tempt us. Our failures and deeds are our own and not at the behest of a supernatural demon.