x2 to what Sento said. You can do them pretty whenever, as long as you listen to your body through every inch of the movement. If you're stretching cold, don't try to reach a "stretch PR", so to speak.
As an example, the very first thing I do in the gym when I get there is a basic variation of this:
It's a five-minute walk for me to get to the gym, so I'm technically doing them after "a warm-up", but I consider them part of my general warm-up before touching the weights. I'm still paying attention to how my hip flexors, glutes/hamstrings, shoulders, and spine feel, and if anything's still tight, I don't try to push it far.
EDIT: Just to be clear, while it's "safe" to stretch a bit before warming up, stretching a cold muscle is one of the easiest ways to cause injury, so if you're going that route, it's worth-repeating that you need to pay extra attention to how deep and how fast you go through the movements.