I have a pc with static IP bought from my ISP and RDP enabled. I was using this PC for development and didn't tell or use it for any communication purpose so it's not possible that someone knew about it. But I got hacked with a ransomware and all my files are encrypted. Fortunately, I have a backup for everything. But I want to know how the hacker knew that there is a server on that static IP that is not attached to any domain or used by any public products (website, web-service ... etc)
I was using this PC for development and didn't tell or use it for any communication purpose so it's not possible that someone knew about it
The entire Internet is regularly port scanned, both by malware, attackers and researchers such as shodan.io. You can not expect any service accessible to the Internet to be unidentified for more than seconds after connecting it.
If you make anything available, secure it. Keep it patched. Disable unneeded features, and so on. Protocols that have a high impact and poor security record, such as RDP, should probably not be exposed directly, but shielded via for instance a VPN, or a SSH tunnel, so that the service is not externally accessible.
Your question is like asking why anyone broke into your house, when you didn't advertise the address in the newspaper or phone book: someone saw it there, and decided to break in.