Must we connect the data pin to GPIO4? Why not some other GPIO?
The sensor uses the 1-wire communication protocol. Originally the Pi driver for the 1-wire protocol was hard wired to use GPIO4. Now you can use any accessible GPIO. The GPIO still defaults to 4 but you can specify another by
dtoverlay=w1-gpio,gpiopin=x
where x is the Broadcom numbered GPIO you want to use.
How does exactly the sensor work?
I have no idea. It communicates the result in digital fashion using the complicated Dallas 1-wire bus protocol. Only 1-wire sensors use this protocol. Other popular sensors such as the DHTxx series do not.
Why do we have to put a resistor between the POWER and DATA pins
You don't unless the sensor is powered from 3V3. You should have an external pull-up to 3V3 of about 4k7. The sensor signals 0 by pulling the DATA line to ground. It signals 1 by letting the signal float to an external voltage. This system simplifies signalling in both directions along one wire. It also allows the device to be powered by 5V but have its DATA line connected to a only 3V3 tolerant GPIO like the Pis.