I can not figure it out. If miners get less and less BTC each halving wouldn't they eventually start decreasing hash power when BTC value stops rising making the blockchain prone to 51% attack?
You are correct in your appreciation, and this will in fact occur. But you have to zoom out the time frame. This process has been delayed by both technological advance (smaller asic nodes) and bitcoin price evolution, but in the long run neither will cope and mining is destined to become less and less profitable until most people leave and the hashrate goes low.
Do know that halving also presses the bitcoin price up due to slower production, but it shouldn't cause it to "double", so its not going to remain as profitable to mine as it was. This is by design, large miners who fail to see this might end losing all their money at the end (not unlike cloud mining).
As for the 51% attack, don't even bother. It may feel like a lower hashrate, but its more expensive as well. Those who remain mining still make it very expensive to try such attacks. You will see it because the hashrate is going up while the earnings will go down, even after it becomes less profitable, because of the asic becoming more efficient and cheaper.
Thing is you won't see as if standing today and simply moving one variable (hashrate down), you have to add the other variables, such as asics getting better. We are entering the asic miner is @ 50T era, from the 10T era. By the time the halving comes those 50T miners will earn like today 25T miners, but spending twice the power.