How does WiFi in android detect if the device has to sign in or not?
The detection url differs between different Android versions.  

For Marshmallow, it uses connectivitycheck.gstatic.com/generate_204, check the code here AndroidXRef - Marshmallow 6.0.0_r1

For Kitkat, it uses clients3.google.com/generate_204
check the code AndroidXRef - KitKat 4.4.4_r1