It appears that in the msys2 shell running under mintty, at least for MINGW64, 'stdin', 'stdout' and 'stderr' all report 0 (false) for 'isatty()', whereas if you open a Windows CMD.EXE prompt and run the same executable, all three file descriptors (0, 1, and 2) return 1 (true).
I'm not convinced this has always been the behavior, as I'm pretty sure I never ran into this until I re-installed msys2.
This is not the correct behavior according to POSIX.1 [IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)], https://pubs.opengroup.org/onlinepubs/9699919799/
At program start-up, three streams shall be predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). When opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device.
My tests indicate that neither stdout nor stdin not fully buffered when running the msys2 bash shell in mintty.
Adding the following to the beginning of your "main()" does make stderr and stdout non-buffered:
(void)setvbuf(stdout, NULL, _IONBF, 0);
(void)setvbuf(stderr, NULL, _IONBF, 0);