Wifi Considerations
Modern wifi networks have several frequency bands, most commonly 2.4G and 5G. Embedded devices and single card computers usually only support 2.4G. This is no problem in most cases, as the main benefit of 5G is higher bandwidth which means you can transfer lots of data quickly. In most cases it is not needed. Some issues with MQTT has still been observed. Also on some Realtek routers it has been observed that you then have to switch the settings on the 2.4G network to legacy mode and deactivate b/g-protection.
Broker and client on different frequency bands
If the MQTT broker host is connected to a wifi on the 5G band, and a MQTT client host is connected on the 2.4G band, then there have been cases where the connection on the client side is bad. It can connect, but it gets disconnected and some times it even loses its wifi connection. This happen for example on ESP32 boards. It is yet to be figured out why it happens.
Recommendations
For a stable connection, make sure that the MQTT broker host and the MQTT client host are connected to the wifi on the same frequency band. This is the only known way to have a stable connection on a local wifi.