[Sony Xperia M] thermate:
I don't know. All I know is that I did these:

Reflash 4.1.2 from flashtool

Boot it, root it, push a busybox on the thing

dd if=/dev/block/platform/msm_sdcc.1/by-name/TA of=/sdcard/TA.img

Pull TA.img from the internal storage to the computer

On phone: busybox md5sum /dev/block/platform/msm_sdcc.1/by-name/TA, on computer: md5sum TA.img, ONLY PROCEED IF CHECKSUMS MATCH! (They matched the first time for me. As a precaution I put them on my Google Drive along with the checksum, they'll be safe there, you should also find a safe place for your own backup in case you want to restore it later.)

Put the phone in fastboot mode, unlock it using the official method, then flash boot.

[*]Start recovery (bashing vol+), flash full ROM from the SD card, then flash Gapps too.

[*]Boot the phone, watch it being stuck on bootanimation.

[*]Pull the battery, start recovery again, wipe /system, flash ROM

[*]Boot phone, watch another 10 minutes of the boot animation

[*]Pull battery, start recovery, wipe everything, notice that /data won't wipe because it won't mount (WTF?)

[*]Do a bit of Googling, realize that recovery is afraid to wipe /data, because the internal storage (/data/media) is inside it, and precious things can be on it (for example the Nandroid backups, the ROM you were about to flash, family photos etc.)

[*]Use "wipe /data and /data/media" in recovery, this really formats the /data partition.

Flash ROM, flash Gapps, reboot phone, be happy with it.

I marked the steps with lime colour in which I am absolutely sure my /data was corrupted, and dark green when I only suspect it.

On second thought, it

may

have something to do with unlocking the bootloader in the official way. As far as I know, unlocking the bootloader destroys all user data on the phone as a security measure (say your stock ROM has a password you set but an attacker could flash an alternate ROM with no password to access all of your precious data. To prevent this you can't flash an alternate firmware without unlocking the bootloader and destroying sensitive data in the process). And as fastboot is a pretty simple and dumb piece of code (all it has to do is write the internal flash), I wouldn't be surprised if it didn't bother creating a filesystem on the /data partition, but instead just zeroed it all out. Their philosopy seems to be "if you know how to unlock the bootloader, you are a developer, and developers know how to format the /data partition". So, if my train of thought here is correct, my /data was "corrupted" in the steps marked with any shade of green, only this doesn't really mean "corrupted", it means "zeroed out with no filesystem".

The recovery's "wipe /data" command means: mount /data, and delete everything except the /media folder inside, because the internal storage lives at this folder, which most people don't expect to lose when wiping /data, for idiotic historical reasons.

So all zeroes -> no filesystem -> recovery can't mount it -> recovery pees its pants in horror and doesn't touch it, because it thinks "Oh my Glob, this partition does not contain a valid filesystem, but it

may

have a corrupted filesystem or one that I don't recognise, and formatting it could destroy my owner's data, which could be inside this hypothetical filesystem's /media directory. Which my owner wouldn't expect and then they would think I am a bad recovery."

------

I just re-read your question. I didn't use any stock software after unlocking, my recovery formatted my /data perfectly for me.