tbf, artillery was pretty inaccurate - by the time it was accurate enough to hit single individuals, sharpshooters were the bigger problem.
But yeah, there’s a reason why flag-bearers have such ridiculous casualty rates. “HERE, SEE MY BRIGHT COLORS WAVING ABOVE MY HEAD? I’M WORTH BONUS POINTS”
I mean, in Roman times (the Republic, you philistine) losing a flag/standard was a huge shame.
Later semaphores meant you could cut off communication by killing the flag bearer. Which would be beneficial in a battle
I don’t know if any of this is true though, just facts I learned from various places and Wikipedia articles. I wouldn’t trust me on this.
Flags in later combat were used for the same reason (and with the same notions of honor and dishonor from losing it) as Roman standards. The flagbearers were around to KEEP THE COLORS HIGH, both to encourage the troops and to give them something recognizable to follow in the chaos of the battlefield. Lost your way? Look for the standard waving at the front of your unit, and follow them forward!
The flagbearers of the US Civil War were separate from the signaling corps, who used different flags and had to run them up and down as needed.
“A man who loses the King’s Colours… loses the King’s friendship.”

I mean, the thing is, artillery is generally pretty inaccurate up until a pretty late point. Even in the US Civil War, explosive shot was the exception, not the norm, and if you hit the unit you were aiming for, much less aiming for any particular rank or file, it was considered a good shot.
Famously, General Sedgewick exposed himself under artillery fire for a prolonged period, reassuring his men that the Confederate artillery couldn’t hit an elephant at the distance they were at.
… he was killed shortly thereafter, but by a hidden sharpshooter, not the artillery.
You might not be able to hit a soldier, but you usually can hit an army.
The flag just gives you something to focus on.
It’s like the urinal cakes. Just being there draws fire, even if it’s a college bar and they mostly miss the urinal.
Flag bearers were largely used for communication. In a hectic battle, distributing orders to your troops was a problem. Flag bearers were essentially a way for orders to be communicated. By looking at the flag (which was really more of a banner, held taut so it wouldn’t wave too much in the wind), you could get a rough idea of what you were supposed to be doing. Its direction, angle, height, and front/back face could be used to communicate orders like “push left”, “push right”, “hold position”, and “retreat”.
Flag bearers weren’t targeted just because they were easy targets… They were targeted because eliminating them meant you were hamstringing your enemy’s communication.