Well I calculated the same thing with Hisuian Goodra's special defense (boosted by nature) against Shadow Rider Calyrex's sp. attack (boosted by nature) and both level 50. So that means the sp. atk of Calyrex is 238 and the sp. def. of Goodra is at 187 without EVs and 222 with EVs. and Calyrex will be using Astral Barrage so the STAB is counted and the power is 120.
So first, max sp.def: (22x120x (238/222)) divided by 50 and then we add 2 = 58,6 or 59 damage. now if we count the STAB we multiply by 1,5 which now equals 87,9 or 88. So with Goodra's hp that are of 155 if there's no EVs to support, it'll end up with 96 hp (61%). If we count the STAB, realistically, it'll end up with 67 hp (43%), which is less than half.
Secondly, we're gonna put the EVs in HP which means the sp.def is back at 187 with the nature boost, but no EVs. (22x120x(238/187)) divided by 50 and then we add 2 again = 69,2 or 69 which is pretty strong for damages. Now, realistically, we calculate the STAB, so multiplying by 1,5 and that gives us 103,8 or 104. So without the STAB, the hp that are left are 118 (63%). and wIth the stab there's 83 hp (44%).
Even if the difference is not huge in percentage, there is still more left AND more hp. And the HP benefit also the defense, so it's more useful in this case I picked to use max out the HP stat.
Also, I would like to add that it depends on the pokemon whether it's better to increase HP or defenses, the Gardevoir you picked had less defense than HP, so it's probably more helpful to put more EVs in defense. However, Gardevoir also have a high sp.def that is higher than it's HP. so if u want more resistance overall you can increase HP and defense and not spend anything on sp.def, or you can share the EVs for the defenses, but the first option is probably better: HP is good against both sp.atk and atk, which makes it more strategic.