Since skeletons cannot swim, skeletons' pathfinding forces them to go directly under you while underwater, which causes their arrows to not go high enough to hit you if the water is too deep, which leads to them shooting themselves.
Steps to reproduce:
- Spawn a skeleton at the bottom of the water that is at least 10 blocks deep, but not outside of the skeletons' "render distance".
- Swim directly above it. Stay on the surface of the water, but do not move horizontally.
- Switch to survival mode. --> The skeleton will try to shoot you and it will keep hitting itself until it dies.
The most obvious fix for this would be to make it so skeletons don't swim directly under you while targeting you.