they are at 0V, the output of the buffer stays 0V, but the relay is being turned on which I am not able to understand.
When the coil current voltage is 0 but the NO contacts are closed, it means the contacts are stuck together from excessive prior corona created by rapid cutoff of an inductive load. When V=LdI/dt exceeds the gap breakdown voltage (BDV) for at least 1 us, an arc occurs. THe gap starts small so with at least 1kV/mm arc, it can be stretched with low voltage drop as the contact tries to go open.
Inspect your relay contact for damage when this occurs and use a flyback diode across each inductive element. The coil does not need a 1N400x and could use a 1N4148
Non−repetitive Peak Forward Surge Current 1.0 A
Pulse Width = 1.0 s 1.0 A
Pulse Width = 1.0 us 4.0 A
The lack of clamp diode on the solenoid appears to be the root cause of your fault condition.
This 1N4148 could also work for the solenoid. The bulk resistance Rs of the diode is inversely related to it's current limit. As this condition is transient the Rs controls the turn off time. Tau=L/Rs where minimum Rs is the slope of the diode VI curve at some point.
There is no harm in using the 1N400x rated for transients > 30A will thus be about 10x slower in releasing the stored energy which is faster with higher resistance. But at least you won't weld your relay contacts together,.
If my assumptions are incorrect, please give more measurement info.
- the 74ALS buffer is redundant and is not required.