I'm trying to understand a minor detail in this proof:
2.21. Theorem (Cantor). For every set $A$, $$ A <_c \mathcal{P}(A), $$ i.e., $A \leq_c \mathcal{P}(A)$ but $A \neq_c \mathcal{P}(A)$; in fact there is no surjection $\pi \colon A \twoheadrightarrow \mathcal{P}(A)$.
Proof. That $A \leq_c \mathcal{P}(A)$ follows from the fact that the function $$ (x \mapsto \{x\}) $$ which associates with each member $x$ of $A$ its singleton $\{x\}$ is an injection. (Careful here: the singleton $\{x\}$ is a set with just the one member $x$ and it is not the same object as $x$, which is probably not a set to begin with!)
To complete the proof, we assume (towards a contradiction) that there exists a surjection $$ \pi \colon A \twoheadrightarrow \mathcal{P}(A), $$ and we define the set $$ B = \{ x \in A \mid x \notin \pi(x) \}, $$ so that for every $x \in A$, $$ x \in B \iff x \notin \pi(x). $$ Now $B$ is a subset of $A$ and $\pi$ is a surjection, so there must exist some $b \in A$ such that $B = \pi(b)$; and setting $x = b$ and $\pi(b) = B$, we get $$ b \in B \iff b \notin B $$
I am confused with the choice of $B$ here. I understand that we could make a surjection this way, after all we are mapping each $a\in A$ to an element of $P(A)$ that does not contain $a$, that is: Something like:
$$1\to\{2,3\}\\ 2\to \{1,3\}$$
And this yields that problematic conclusion. I understood the proof, but I don't understand why this choice of $B$ proves that there is no surjection. That is: Why couldn't we construct $B$ in another form such that the surjection is achievable? Does the sole existence of this construction of $B$ denies the surjection? Why?
The better way to formulate the proof is not by contradiction, but rather by contrapositive: let $\pi\colon A\to\mathcal P(A)$ be any function, we define a set $B_\pi\in\mathcal P(A)$ such that $\pi(a)\neq B_\pi$ for all $a\in A$. In other words, we show that $\pi$ is not surjective.
Now, the important thing to note is that the definition of $B$ depends on $\pi$, and it works for any $\pi$. It's not just for surjective functions; and different $\pi$ will produce different $B$'s.
Let's look at two examples:
Example I:
Then we define $B$ to be $\{a\in A\mid a\notin\pi(a)\}$, which in turn translates with this specific $\pi$ to be $B=\{a\in A\mid a\notin\{a\}\}$. Of course, this $B$ has to be empty. But lo and behold, $\pi(0),\pi(1)$ and $\pi(2)$ are all non-empty. So $B$ is not in the range of $\pi$.
Example II:
What does the definition of $B$ gives us now? It's the set $\{n\mid\ n^2\nmid n\}$, which is exactly $\Bbb N\setminus\{0,1\}$. But now we ask if there is a number $n$ such that $n^2$ divides all the natural numbers except $0$ and $1$? Since every number divides $0$, the answer is easily negative; but also by arguing through prime numbers if you prefer: $n^2\nmid 2$ for any natural number except $1$, but since $1^2\mid 1$, and $1\notin B$, it is impossible that $B=\pi(1)$, so $B$ is not $\pi(n)$ for any $n$.
TL;DR
So to recap, $B$ is defined from $\pi$ to conclude that $B$ is not in the image of $\pi$. This definition depends on $\pi$, but it works for every $\pi\colon A\to\mathcal P(A)$.