Re: "illegal, illogical, and inexplicable"
Well, only if you ignore geography.
First, as others have pointed out, EU != NATO.
Second, as a direct result of Putin's actions, there are today more NATO troops on Russia's borders than ever before. Thousands of troops, ships and aircraft from Spain, Denmark, the Netherlands, Britain and America, among other countries, have been deployed to Poland, the (formerly Soviet) Baltic states, and the Baltic Sea.
Third, if Putin succeeds in his declared aim of conquering and annexing Ukraine, that will give him new borders with Poland, Slovakia, Romania and Hungary. That simple geographical fact will at a stroke add around 200,000 more NATO troops sitting directly on his border. That's close to the total number of troops he's deployed in and around Ukraine.
Fourth, after decades of undermining western unity by his successful fostering of neo-fascism in places such as Hungary, Poland, the United States and Britain, he has suddenly and vastly reinforced it. The liberal/democratic order of Western Europe looks happier and more secure now than it has done at any time since the EU enlargement of 2004.
If "keeping NATO troops away from his borders" is the aim, it's harder to imagine - short of actually invading a NATO member - how he could have scored a bigger own-goal than this.