The following only works as a pure test. Both X and Y must be known.

  cousin(X,Y) :- \+(X = Y), \+ sibling(X,Y), grandparent(Z,X), grandparent(Z,Y).
In a Prolog dialect that uses not instead of \+:
  cousin(X,Y) :- not(X = Y), not(sibling(X,Y)), grandparent(Z,X), grandparent(Z,Y).