Android Nexus 5 knows password of WiFi he was never connected to! I just bought a new Nexus 5 after using a Nexus 4 for about a year.

After turning it on and using it at work, I go home and as soon as I turn the WiFi on the phone it connects to my home network without having to insert any password.

I have never used it before at home and I did not insert the password on that phone. To verify I went to a friend of mine's place where I had used the old Nexus 4 and tried again and voila' the phone connects to the network again.

Does anybody know if it's an expected behaviour or does it sound strange to you as well?

What could be the reason? The only thing I could think of is that Google is storing details about the WiFi you connect to on your Google account. Can anybody confirm? Is this even legal?
Did you backup/restore your settings to/from Google? If so, that's why you can connect to these wireless networks. One of the things that gets backed up is the wireless network passwords so when you restored them back on your new device it is able to connect.

Android has built in backup functionality. It offers to backup settings (including wifi settings) automatically from each device. When you go through the set-up on a new device it then gives you the option to restore these settings. If you had this configured (I think it's enabled by default) then your wifi settings would have automatically been backed up on your Nexus 4 and restored to your Nexus 5.