A protein shake can be taken either before or after a workout. In people who already get enough protein during the day, taking it right before exercise or right after exercise appears to lead to very similar results for muscle growth and strength.
What seems to matter most is total daily protein intake and having protein available around the time you train. There does not appear to be a very narrow window where protein must be taken immediately after exercise to work.
Taking a shake after a workout can still be a practical choice, especially if it helps you recover, meet your daily protein needs, or avoid skipping a meal. Taking it before a workout may also be reasonable if you have not eaten for several hours or if it fits better with your routine.
Protein shakes are not required for everyone. Whole foods can also provide protein. Avoid taking more supplements than needed, especially if you have kidney disease or another chronic condition. Speak with a registered dietitian or doctor for personalized guidance.