Try this modification which is based on your original code.
Using the trans function will locate your drawn LINE at the same coordinates P1 & P2 selected prior to changing the UCS.
Also keep in mind that the resulting rotation angle of the TEXT again is calculated on the current UCS coordinate angle between P1 & P2 prior to changing the UCS. This is what determines (again per your code) the rotation of the placed TEXT.
I purposedly modified the TEXT to show what that rotation angle was for reference.
(DEFUN C:CT (/ ANG ANG1 c1 P1 P2 P1w P2w texteval) ; localize variables
(SETQ
P1(GETPOINT "\n PICK FIRST POINT :")
P2(GETPOINT P1 "\n PICK SECOND POINT :")
ANG(ANGLE P1 P2)
c1(/ 180 pi)
ANG1(* C1 ANG)
)
; angle is calculated based on current UCS P1 & P2
; translate points from current UCS to World
(setq P1w (trans P1 1 0)
P2w (trans P2 1 0)
)
; change the UCS to another using selected P1 & P2 points
(COMMAND "_.UCS" "3" P1 P2 "")
; translate points from World to new current UCS
(setq P1 (trans P1w 0 1)
P2 (trans P2w 0 1)
)
; draw line based on these coordinates
(COMMAND "_.LINE" P1 P2 "")
; save current texteval
(setq texteval (getvar"texteval"))
; if 0 change to 1
(if(zerop texteval)(setvar "TEXTEVAL" 1))
; place text in middle of line drawn showing calc rotation
(COMMAND "_.TEXT" "_J" "_MC" "_M2P" P1 P2 8 ANG1 (strcat "Text Rotation is : " (rtos ANG1 2 1)))
; restore original texteval
(setvar"texteval"texteval)(princ)
) ; defun