The adjunction space $X\cup_f Y$ can be created in two steps.
First, the points of $X$ are glued together according to the values of $f$, that is,
$x\sim y$ iff $f(x)=f(y)$.
Points of $X\setminus A$ remain unglued.
The topology on $X':=X/\mathord{\sim}$ is such that a set $U$ is open in $X'$
iff $f^{-1}[U]$ is open in $X$ (we used the definition of the quotient topology).
We can naturally translate $f\colon A\to Y$ to a one-to-one map $f'\colon A/\mathord{\sim}\to Y$
by letting $f'([x])=f(x)$ for $x\in A$.
In the second step, points of a disjoint union $X'\cup Y$ are glued together
according to a one-to-one correspondence $f'$, that is, $[x]$ is identified to $f(x)$ for each $x\in A$.
A subset $U$ of the obtained space $X\cup_f Y:=X'\cup Y$ is open iff
sets $U\cap X'$ and $U\cap Y$ are open in $X'$ and $Y$, respectively
(again by the definition of the quotient topology).
We should realize that two topologies we have on the domain and on the range of $f'$ can be completely different.
The resulting topology on the common part of $X\cup_f Y$ (corresponding to pairs of points identified by $f'$)
is the finest topology that is coarser from both.
These two steps can be taken at once. The space $X\cup_f Y$ is then defined as a disjoint union of $X\setminus A$ and
$Y$, and a set $U\subseteq (X\setminus A)\cup Y$ is open in $X\cup_f Y$ iff
$(U\setminus Y)\cup f^{-1}[U]$ is open in $X$ and $U\cap Y$ is open in $Y$.
To correctly define adjunction space $(X\cup_f Y)\cup_g W$ using $g\colon Y\to W$,
we should ensure that $Y$ is a subspace of $X\cup_f Y$.
To this end we need that the topology on $A/\mathord{\sim}$ is finer than that on $f'[A/\mathord{\sim}]=f[A]$.
Equivalently, for every open set $U\subseteq f[A]$, $f'^{-1}[U]\subseteq A/\mathord{\sim}$ is open, and hence
$f^{-1}[U]\subseteq A$ is open.
This is true as we have assumed that $f\colon A\to Y$ is continuous.
So we can define $(X\cup_f Y)\cup_g W$ as a disjoint union of $(X\cup_f Y)\setminus Y$
and $W$, which is in fact a disjoint union of $(X\setminus A)$ and $W$.
A set $U\subseteq (X\setminus A)\cup W$ is open in $(X\cup_f Y)\cup_g W$ iff
$(U\setminus W)\cup g^{-1}[U]$ is open in $X\cup_f Y$ and $U\cap W$ is open in $W$.
Further, $U':=(U\setminus W)\cup g^{-1}[U]$ is open in $X\cup_f Y$ iff
$(U'\setminus Y)\cup f^{-1}[U']=(U\setminus W)\cup f^{-1}[g^{-1}[U]]$ is
open in $X$ and $g^{-1}[U]$ is open in $Y$.
Since $g\colon Y\to W$ is continuous, if $U\cap W$ is open in $W$ then $g^{-1}[U]=g^{-1}[U\cap W]$ is open in $Y$.
We can conclude that $U\subseteq (X\setminus A)\cup W$ is open in $(X\cup_f Y)\cup_g W$ iff
$(U\setminus W)\cup f^{-1}[g^{-1}[U]]$ is open in $X$ and $U\cap W$ is open in $W$.
The adjunction space $X\cup_{g\circ f}W$ is correctly defined, since $A$ (which is the domain of $g\circ f$)
is a subspace of $X$.
It is again a disjoint union of $X\setminus A$ and $W$, and a set $U\subseteq (X\setminus A)\cup W$ is open
in $X\cup_{g\circ f}W$ iff $(U\setminus W)\cup (g\circ f)^{-1}[U]$ is open in $X$ and $U\cap W$ is open in $W$.
We are done since $(g\circ f)^{-1}[U]=f^{-1}[g^{-1}[U]]$ and we can see that $U$ is open in $X\cup_{g\circ f} W$
iff it is open in $(X\cup_f Y)\cup_g W$.
Let us finally note that we have not used the assumption that $A$ is closed in $X$.
This assumption is sometimes included in the definition of the adjunction space.
If this is our case then we should, when considering the adjunction $(X\cup_f Y)\cup_g W$,
to check that $Y$ is a closed subspace of $X\cup_f Y$.
This is true if $A$ is closed in $X$:
Let $U$ be the complement of $Y$ in $X\cup_f Y$.
Then $U=X\setminus A$ is open in $X\cup_f Y$, as $(U\setminus Y)\cup f^{-1}[U]=U$ is open in $X$
and $U\cap Y=\emptyset$ is open in $Y$.