This paper presents the measurement of fiducial and differential cross sections for both the inclusive and electroweak production of a same-sign $W$-boson pair in association with two jets ($W^\pm W^\pm jj$) using $139\,\mathrm{fb}^{-1}$ of proton--proton collision data recorded at a centre-of-mass energy of $\sqrt{s}=13$ TeV by the ATLAS detector at the Large Hadron Collider. The analysis is performed by selecting two same-charge leptons, electron or muon, and at least two jets with large invariant mass and a large rapidity difference. The measured fiducial cross sections for electroweak and inclusive $W^\pm W^\pm jj$ production are $2.92 \pm 0.22\, \text{(stat.)} \pm 0.19\, \text{(syst.)}$ fb and $3.38 \pm 0.22\, \text{(stat.)} \pm 0.19\, \text{(syst.)}$ fb, respectively, in agreement with Standard Model predictions. The measurements are used to constrain anomalous quartic gauge couplings by extracting 95\%\ confidence level intervals on dimension-8 operators. A search for doubly charged Higgs bosons (H^{\pm\pm}) that are produced in vector-boson fusion processes and decay into a same-sign $W$ boson pair is performed. The largest deviation from the Standard Model occurs for an (H^{\pm\pm}) mass near $450\,\mathrm{GeV}$, with a global significance of 2.5 standard deviations.