Yes, there is a difference.
In the 1st one, you are asking why he/she is not coming.
In the 2nd one, your are ordering/telling to him/her that is not coming, and then asking why.
The 2nd one should be:
Me han dicho que esta tarde no vienes, ¿por qué?
Someone told me you are not coming, why?