Your code:
likes(john,mary). % {1}
likes(mary,jane). % {2}
likes(l,k). % {3}
likes(X,Y) :- % {4}
likes(X,Z), % {5}
likes(Z,Y). % {6}
The query likes(john,Y)
proceeds as follows:
likes(john,Y)?
%% {1} Y = mary. ; redo
%% {4} likes(john,Y) :-
%% {5} likes(john,Z)?
%% {1} Z=mary.
%% {6} likes(mary,Y)?
%% {2} Y=jane. ; redo
%% {4} likes(mary,Y) :-
%% {5} likes(mary,Z2)?
%% {2} Z2=jane,
%% {6} likes(jane,Y)?
%% {4} likes(jane,Y):-
%% {5} likes(jane,Z3)?
%% {4} likes(jane,Z3):-
%% {5} likes(jane,Z4)?
............
and that's what you see in the debugger.
To prevent this behaviour, rename your transitive closure predicate, as follows:
likes(john,mary). % {1b}
likes(mary,jane). % {2b}
likes(l,k). % {3b}
pals(X,Y) :- % {4b}
likes(X,Z), % {5b}
pals(Z,Y). % {6b}