Unable to communicate to a local WiFi with mobile data enabled
Android has an option to switch to cellular data if the wifi connection is low speed/signal. I suspect that the same mechanism triggers when the WiFi network does not have a default gateway defined, so all outgoing connections by default choose the source IP corresponding to the cellular interface.
To ensure you can talk to WiFi hosts where there is no internet connectivity, first query for the WiFi IP address then use it explicitly as the source IP in the app.
If you leave it default, ougoing connections would happen with the cellular IP address which then would go to the cellular gateway.
Alternatively, if you can root the device, you can then copy the tcpdump binary and capture the traffic over the WiFi and cellular interface to confirm the source IP of packets sent by your app. Instructions for this fall out of this question scope but here is a good how to: https://www.andreafortuna.org/2018/05/28/how-to-install-and-run-tcpdump-on-android-devices/