Hash function composition - security level
z(x) is equivalent to f(x) for your use case. MD5 has known collision vulnerabilities, so your overall output will suffer from the same vulnerabilities. Also since the output is 128 bits long it is discarding the additional security margin of having a longer hash output. 

Using SHA-512 alone is safer. If length extension attacks are an issue either use SHA-512/256, SHA3, Blake2b, HMAC, or another secure hash function immune to such attacks.