Why does this happen and, most importantly, how to avoid this?
You should ask this question on Security.SE.
To avoid corruption you should make backups.
In information technology, a backup, or the process of backing up,
refers to the copying and archiving of computer data so it may be used
to restore the original after a data loss event. The verb form is to
back up in two words, whereas the noun is backup.
Writable digital optical media such as CD-R and DVD-R could be corrupted even by sunlight. To avoid this you might use something like double backup strategy. However, nowadays, we have such beautiful online methods to backup photos, like Instagram or other online services. For example, behind Google Drive there are large amount of data centers. Every one of your photos will be stored on the Google File System (GoogleFS or GFS) on servers hosted in these data centers. This filesystem was designed by Google to protect users from losing data. Your photos will be saved in three exemplars in three different geographic locations, to protect against data loss because of local disasters from lightning, tsunami, earthquake, etc.
Try to use multiple online services simultaneously (such as megaupload, dropbox, wuala, 4shared, etc.).
Thereafter, for the greatest peace-of-mind that none of your photos were modified or corrupted, you would use checksums to verify your data integrity.
A checksum is a small-size datum from a block of digital data for the
purpose of detecting errors which may have been introduced during its
transmission or storage.
The best way is to use cryptography for such task. Use the latest stable hash functions, such as SHA-256 or SHA-512. Older algortihms, such as MD5, are now considered insecure. A modern attacker could make forgery of your data with the same md5sum.
When you are done, you will have a distributed backup system which will not be easily broken, even by the most sophisticated and dedicated attackers (such as nation state -backed attacks).
Two DVD copy with identical datas inside:
1. Photo1.jpg
2. Photo2.jpg
3. Photo3.jpg
...
999. Photo999.jpg
1000. SHA256SUM
Where this SHA256SUM shall contain something like:
e5347dce99eb8cf694cf708d4a17d83abb3ec378241b5878c0abdab045859b24 Photo1.jpg
b497a12b608def869a0429d7e6bbbd112bd413256201647a5aff6773de3b7bd9 Photo2.jpg
b15b0d99bf8135286f444fc62bcf70278a89e60650252ab2bd3b6fffd40c4255 Photo3.jpg
...
209732fbdb499f0cad6fd3311b45185667bbb40e501106997d3ac2c49cb30a7e Photo999.jpg
The lines 209732fbdb499f0cad6fd3...
are unique hashes of your photos. When one bit of your photo becomes corrupt, this hash will be changed to another, so you could test hashes against this list to be calm that your photos are keeping integrity.
Secondly, all of this photos and this SHA256SUM-hashes file are uploaded to e.g. dropbox and somewhere else.
Now, you have 5 copies of your photos. 2 off-line, 2 on-line, 1 on your current hard drive.
The scheme might be evolved to something more robust of course. Your imagination is your trump card.