Use a = r"$\sin (x)$" Or alternatively convert variable a to b, like so:
import matplotlib.pyplot as plt
ax = plt.gca()
x = [1,2,3,4,5,6]
y = [324,456,6,78,2,54] # cramming numbers on my keyboard
a = "\sin(x)"
b = r"$"+a+"$"
ax.plot(x, y, label=b)
ax.legend()
plt.show()