For relays in general there are some nuances with the Pi that explain why you are seeing this behavior and what you can do about it.
On the Pi's GPIO header, there are a couple of pins marked 3.3v and a couple marked for 5v. These pins are ALWAYS powered (as long as the Pi is running). You can't turn them on or off.
Then there are the rest of the GPIO pins ... which only provide 3.3v power, but you can control whether they are high or low (on or off).
This creates a challenge... most of these small relays want 5v power and either the 3.3v isn't sufficient or if the relay works it may be unreliable. (Arduino's provide 5v power natively so they don't have this issue.)
The solution is to add a transistor to the circuit. This will let you use 3.3v power to control the flow of 5v power... and the 5v power can be used to control the relay.
The transistor has 3 pins... named "collector", "emitter", and "base" (sometimes you'll see the letters "C", "E", and "B" on schematics. The transistor will let power flow from the collector to the emitter ... depending on the state of the "base".
The collector & emitter will supply the 5v power ... which will only flow when power is applied to the base (3.3v power). This way when you toggle the GPIO pin on or off, it will result in the transistor supply 5v power to the relay.
There are a few types of transistors (PnP vs. NpN) and you should probably do a web search on "how transistors work" to understand them. Or "how to use transistors to control a relay using a raspberry pi" would be a good search.
There are relay boards made specifically to be compatible with the Pi. Those boards already incorporate transistors into the circuit design -- so they correctly deal with the power needs.
This is really just the basic idea.
HOWEVER ... there are usually a few extra components added in such as diodes and or resistors for protection. If you do a web search you can find articles that explain the basics, illustrate the circuits, and also show where you should add an additional component for protection (and why).