At some point, Tropical Fish, Salmon, and Cod simply stop moving and at best only spin around. This happens even if the player is nearby. The swimming animation however continues to play.
The video below shows how some of the salmons didn't move, but just spun around.
To reproduce
(from MC-208729)
Create a body of water of any size. I used a 8 x 8 x 5 box
Fill it with tropical fish (you want at least a couple schools, I did about 100 fish)
Wait. Some fish stop moving within a couple minutes. Within 6 or 7 minutes, most tropical fish will either be crowding into a corner or have stopped moving entirely. The larger fish seem to take longer, at least when densely packed together.
Related issues
is duplicated by
Attachments
Comments

I summoned some in a pool of water and saw them spinning just like in your video. While watching them I noticed their general movement has changed. They float up and down to a greater degree, and they were constantly running into each other head first but not altering their path to go around the other fish.
Yeah I saw them headbutting as well xD

This seems to affect all fishes, but mostly salmons.

Since my bug report was closed as a duplicate of this, could you update the description to include some if the information I provided in mine? Like reproduction steps

In 21w10a. If MC-212687 is going to be counted as a duplicate, could the title and description be updated to include Squids and Glow Squid? Because it applies to both of them as well.
And for both squids this only seems to happen when far away, if you get close to them they resume normal behavior, unlike the videos with the salmon and tropical fish

Backing up what I said last week, I've attached a video showcasing how this bug affects both kinds of squid. It's vastly different than what OP is describing happening to fish, as it always happens and depends solely on the player's distance, not at all random. So either the other bug should be reopened or this bug needs to be updated to include the squid issues
[media]
I think it has its own ground to stand as a separate bug really

Affects 21w15a, I still think the title should be updated based on my previous comments ^

In 21w16a, in spectator mode both fish and squid don't move, I guess because they don't detect a nearby player. As soon as I go to creative, they move again. Note that Axolotls still move while the player is in spectator mode.
[media]

In 21w17a

In 21w18a
@Orbic I changed the title now 😃
The squid issue seems unrelated. Could you please file a separate ticket for it?
Edit: I've reopened MC-212687, it's going to be used to track the squid issue from now on.

In 1.18. pre-1

In 22w05a

Confirmed with 22w42a

Confirmed in 1.20 Release Candidate 1.

Can confirm 1.21.2 Pre-Release 4.
Not sure if I just never noticed it or it became more visible due to the bigger fish size.