Hash of same value with the same algorithm is always the same - this is why it is ok to compare just hashes to verify if values are definitely different (if hashes are the same it may still mean values are different, but using sufficiently long hash like SHA256 it may be safe enough to assume that values are the same for password verification).
Most likely you have bug in getting original values to be represented the same way (i.e. non-trimmed spaces, different encoding,...) and that causes hashes to be different.
Note MD5 is generally not acceptable for hashing passwords due to known weakness.