Suppose we are given a Turing machine e terminates with result 0 or 1 on all inputs, such that e(n)=0 when n∈A and e(n)=1 when n∈B. Consider the algorithm F that returns a Turing machine for a given natural number:halt(k) is the machine that terminates with result k on every input.
F(n):={halt(1) when e(n)=0halt(0) when e(n)=1
Because e terminates on all inputs, so does F. By construction e(F(n))=e(n) for each input n: Consider the case that e(n)=0, then F(n)=halt(1). halt(1)∈B because
ϕ┌halt(1)┐(┌halt(1)┐)=halt(1)(┌halt(1)┐)=1
but then e(F(n))=e(halt(1))=1=0=e(n). The same argument applies to e(n)=1.
By the second recursion theoremhttps://www.math.ucla.edu/~ynm/lectures/2009csl.pdf, there exists a Turing machine f realizing F applied to its own Gödel number, that is, ϕ┌f┐≃ϕ┌F(f)┐. Because F(f) is halt(0) or halt(1), both constant, ϕ┌f┐ is constant as well, say with value k. Hence
ϕ┌f┐(┌f┐)=k=ϕ┌F(f)┐(┌F(f)┐)
so either both f and F(f) lie in A, or both lie in B. In either case e(f)=e(F(f)). However, e(n)=e(F(n)) for all n.