Apart from the hat over the $\sigma$ in the first instance, these are examples of a common formula. In both cases there is a square root of a fraction; the numerator is a variance $\sigma^2$ or its estimated value $\hat \sigma^2;$ and the denominator--as it turns out--can be understood as the squared length of a vector of explanatory values in the simplest kind of regression model. Compare the red equalities in the two highlighted equations below.
Consider the model $$y_i = \beta x_i + \varepsilon_i\tag{1}$$ where $\beta$ is to be estimated from data $(x_i,y_i)$ and the $\varepsilon_i$ are assumed to be uncorrelated zero mean random variables all of variance $\sigma^2$ (which is not known). The Ordinary Least Squares estimate is
$$\hat \beta = \frac{\sum_i x_i y_i}{\sum_i x_i x_i} = \frac{\sum_i x_i y_i}{|x|^2}$$
(using a simplified vector notation for the sum of squares of the $x_i$ in the denominator, which we may interpret as the squared Euclidean length of the vector $(x_i)$). Because
$$\operatorname{Var}(y_i) = \operatorname{Var}(\beta x_i + \varepsilon_i) = \operatorname{Var}(\varepsilon_i) = \sigma^2$$
and the covariances of distinct $y_i$ and $y_j$ are zero, compute that
$$\operatorname{Var}(\hat\beta) = \operatorname{Var}\left(\frac{\sum_i x_i y_i}{\sum_i x_i x_i}\right) = \sum_i \left(\frac{x_i}{|x|^2}\right)^2 \sigma^2 = \frac{|x|^2}{\left(|x|^2\right)^2}\sigma^2 = \frac{\sigma^2}{|x|^2}.\tag{2}$$
In the special case where $x_i=1$ for all $i,$ $|x|^2 = \sum_i 1^2 = n$ and the model is
$$y_i = \beta + \varepsilon_i$$
with
$$\hat \beta = \frac{\sum_i (1)y_i}{|x|^2} = \frac{\sum_i y_i}{n} = \bar y,$$
whence
$$\operatorname{Var}(\bar y) = \color{red}{\operatorname{Var}(\hat\beta) = \frac{\sigma^2}{|x|^2}} = \frac{\sigma^2}{n}.$$
Taking square roots gives the second formula in the question. Bear in mind the origin of the denominator $n:$ it is the squared length of the vector of explanatory variables $(x_i = 1).$
The first formula arises by fitting the model
$$y_i = \alpha + \beta x_i + \varepsilon_i = \alpha z_i + \beta x_i + \varepsilon_i$$
(where $z_i=1$ for all $i$) in two steps. In the first step, both $y$ and $x$ are fit to $z$ using the simple model $(1)$ and then are replaced by their residuals. (Please see https://stats.stackexchange.com/a/46508/919 and https://stats.stackexchange.com/a/113207/919 for the justification and explanations of this fundamental step, which is called "controlling for" or "taking out the effect of" the variable $z.$)
In other words, $y_i$ is replaced by $y_{\cdot i}=y_i - \bar y$ and $x_i$ is replaced by $x_{\cdot i}=x_i - \bar x.$ Because this removes all the discernible effects of $z,$ $\alpha$ is no longer needed and we are left to fit the model
$$y_{\cdot i} = y_i - \bar y = \beta (x_i - \bar x) + \varepsilon_i =\beta x_{\cdot i} + \varepsilon_i.$$
This, too is in the form of model $(1).$ Formula $(2)$ states
$$\color{red}{\operatorname{Var}(\hat \beta) = \frac{\sigma^2}{|x_\cdot|^2}} = \frac{\sigma^2}{\sum_i \left(x_i - \bar x\right)^2}.$$
Taking square roots gives the first formula in the question, except here we are using $\sigma$ instead of $\hat \sigma.$
This leads us to the last unresolved issue: when you know (or assume the value of) $\sigma,$ there's nothing left to do: we have our standard errors of estimate. But when you don't know $\sigma,$ about the only thing you can do (short of an infinite regress where you try to estimate the standard error of $\hat \sigma$ and so on) is to replace the occurrence of $\sigma^2$ in formula $(2)$ by its estimate $\hat\sigma^2.$