Let $u_t$ be the random walk
$$ u_t = u_{t-i} + \varepsilon_t $$
where $\mathrm{E}[\varepsilon_t]=0$ and $\mathrm{var}[\varepsilon_t]=\sigma^2$ , i.e. $\varepsilon_t$ is stationary.
Now let
$$X_t = \alpha u_t +\nu_t$$
and
$$Y_t = \beta u_t + \eta_t$$
where $\nu_t$ and $\eta_t$ are stationary processes similar to $\varepsilon_t$
Then both $X_t$ and $Y_t$ are non stationary because they are linear functions of the non-stationary (stochastic trend) variable $u_t$.
However
$$\beta X_t - \alpha Y_t = \beta \nu_t - \alpha_t \eta_t $$
is a linear combination of the stationary disturbances and is therefore stationary. When this happens $X_t$ and $Y_t$ are said to be cointegrated. $X_t$ and $Y_t$ are said to contain the same stochastic trend.
The idea behind the Dickey-Fuller test is to estimate a regression which estimates the ratio of $\alpha$ and $\beta$ and test if the estimated residuals are stationary. These residuals do not follow a standard distribution.