I'm not sure why you need to play with theta, unless you care about the orientation. If you just want the line to become horizontal, rotate an angle of -theta should serve the purpose.
The reason that it does not lie on the x axis is because the rotation matrix is centered on origin. Therefore, once rotated, you need to move it onto the x axis.
I modified your program a little bit and put it below. I just used the -theta and the main change is at the end, where I compensate for the displacement after I did rot*X
X = [-2 -1 1 2;0 -1 -3 -4];
rot = [cos(theta) -sin(theta); sin(theta) cos(theta)];