Controlling 5V Pushbutton switch fails with Triac
You mention "TRIAC".

A TRIAC is a double thyristor and a thyristor is a switching transistor type device that you can switch ON by providing a current through it's gate but you can only switch it OFF if you interrupt the current that it is switching !

I think you are switching a DC signal (the 5 V you measure) so even if you turn the gate signal off (like you do) it will stay ON no matter what. TRIAC switches are for switching AC currents, not DC !

I suggest you get an optocoupler with a phototransistor, not one with a TRIAC / thyristor !