Relay switches to ON/OFF rapidly
There is so much possibility of what is going on:

The GPIO sending PWM signal
The relay doesn't get sufficient voltage
The relay doesn't get sufficient current
The relay somehow damaged?

Relay has specification such as:

Working input rated voltage.
Power consumption (insufficient current can get relay stop working).
Rated voltage contact pin (using the contact pin with voltage over than intended can damage the relay).
Rated Current for contact pin.
Typical resistance.
Relay minimum time to contact. (only in specific relay)
Typical life (usually typical value of contact life on/off)

And relay has a drawback such as:

EMF.
Capacitance.
Resistance.
Inductance.

Because after all the relay is a coil.
so back in your drawing, what is your relay spec? how much current did you draw from the relay? how much current you can provide to relay? Did you check all possibilities?