K=PD[X[1,5,2,4],X[5,3,6,2],X[3,1,4,6]]

t1=K /. X[i_,j_,k_,l_] :> A P[i,l]P[j,k]+B P[i,j]P[k,l]

t2=Times@@t1

t3=Expand[t2]

t4=t3 //. P[a_,b_]P[b_,c_] :> P[a,c]

t5=t4/. {P[a_,a_] :> d, P[a_,b_]^2 :> d}

t6=Expand[Simplify[t5/d /. {B->1/A, d->(-A^2-1/A^2)}]]

g