The hamstrings are the muscles of the back of the thigh. The muscle group consists of three main muscles: semitendinosus, semimembranosus and biceps femoris. Yes, that's right, you have biceps in the back of your legs. Congratulations. Part of adductor magnus is also considered hamstring.
Leg curls work your hamstrings through knee flexion. Romanian deadlifts work your hamstrings through hip extension. Why do both of these different movements train the same muscles? The answer is that the hamstrings muscles have most of their origin points in the pelvis and their insertion points below the knee (for those who haven't studied anatomy, "origins" and "insertions" are both points where a muscle is connected to a bone via a tendon). The pelvic origin in the ischial tuberosity means that shortening the hamstrings from that end causes hip extension, the primary movement in all hinge-based movments (deadlifts, RDLs, goodmornings, hyperextensions).
In my opinion, things get a little more interesting around the knee joint.
The hamstrings, at their insertion points, wrap around behind the knee, and then attach onto the sides of the tibia. Semimembranosus and semitendinosus both attach on the medial side of the tibia, and biceps femoris attach on the lateral side. The angle that each muscle comes in, wrapping around to the side of the knee from behind, indicates that if the knee joint wasn't two adjacent balls in two adjacent sockets, but was a single ball-and-socket joint, then semitendinosus and semimembranosus would internally rotate the knee, and biceps femoris would externally rotate the knee. In practice, it is through the combined effort of all the hamstring muscles trying to rotate the knee in opposing directions that causes knee flexion. A fascinating little contraption the knee joint is.
A lateral view of the knee joint showing where semitendinosus and semimembranosus
insert into the tibia, just below the knee istelf.
Biceps femoris is interesting in its own individual way. Unlike semitendinosus and semimembranosus (as an aside, I'm rapidly getting sick of typing out these names) which just have one main origin and one main insertion, biceps femoris has two main origins. Biceps femoris is broken down into two heads: the long head and the short head. The long head has the conventional hamstring origin point at the ischial tuberosity, making it contribute to hip extension. However, the short head's origin point is on the femur, meaning that the short head of the muscle is mostly only involved in knee flexion. This gives some credibility to the claim that leg curls are an important exercise.
So, there you have a slightly more in-depth look at how the hamstrings work than the simple explanation that they do hip extension and knee flexion. Did your brain survive the read?