You should never compare floating point values via
==. That's because minor floating point errors will cause the equality to fail sometimes - just as you're experiencing.
Based on what you're doing, you typically want to verify that some value is "sufficiently close" to some other value.
In your case, you could do something like:
if abs(linear_velocity.y) < 0.001:
... or something similar...