Holding a stretch is not necessary to get the benefit. A stretch that is held is also known as a static stretch. There is no harm in stretching this way as long as there is no pain.
Stretching before exercise is not necessarily beneficial. Performing static stretches before exercise may worsen performance when doing activities like sprinting. Holding static stretches tire out your muscles.
Instead warming up with dynamic stretches are recommended. Dynamic stretches are like an extension of your workout but at a lower intensity. A recommended warm-up may be a brisk walk, walking lunges, leg swings, and high steps.
Stretching after exercise is an optimal time to stretch. After exercise, people are more flexible due to the increased circulation to muscles and joints. If you use static stretches, this is the time to do them as you will get the most benefit from them now.
It is not crucial that you stretch before or after a workout. It is just important that you stretch at some point in time. This can be when you get out of bed or during breaks at work. Stretching should be a part of a regular routine.