The bug stopped reproducing after installing bash 5.1-2+deb11u1 from stable-proposed-updates (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1003012).
But one question is still open: why did the same script behave differently with the same input data? I think bugreport can be completely closed after the bash upstream maintainer answers this question. Regards, Vladimir Vinogradov