You ask a good question: first off, let's consider a man standing on the ground. How does he know that there is a gravitational force present? I don't know. But if he's allowed to pick up an object, and drop it, then he can at least assume that there's a gravitational force on the object; that it's in the up-and-down direction (your question is in the left-to-right direction presumably, but it makes no difference); and that it's magnitude is $9.8$ m/s$^2$. So he writes that $\vec{g} = - 9.8 \hat{y}$. And if he knew 1) the second law $\vec{F} = m\vec{a}$, and 2) that there were no other forces present, he writes $\vec{F} = m\vec{g}$ or maybe $\vec{F}_g = mg \hat{y}$ assuming $g = -9.8$, or if you want to keep $g = 9.8$ then add a negative so $\vec{F}_g = -mg \hat{y}$
He then could assume that this force is acting on himself as well, although he's standing on the ground and not moving (nor can really perceive it). So given he already knew that $\vec{F}_{\text{net}} = m \vec{a}$, he'd have to conclude another force on the left-hand side (the normal force) so that $\vec{0} = \vec{0}$. Or, given, he already knew $\vec{F}_{\text{net}} = m \vec{a}$ and the normal-ground force, he could assume some sort of gravitational force. (What I'm trying to get at here, is that "foundation" - literally the ground - is important - but regardless, to conclude that a gravity was acting on you...well, it's kind of hard to judge yourself...but if you pick up other objects and drop them...you could recognize the gravity.)
Now to your example: According to $S$ the net force on the object is $\vec{F}_{\text{net}} = 5m \hat{x}$. The full acceleration $\vec{a}$ was in the $x$-hat direction anyways, so we didn't need to worry about gravity (maybe the object is on a table). According to $S'$, he has to be able to figure out that there's a gravity present in his frame of reference/perspective. He's stationary from his perspective (as we are too from ours, even though $-9.8$ m/s$^2$ is acting on us - yet we had to figure that out). If he were to pick up an object and drop it, it would accelerate backwards at $-1$ m/s$^2$ (in addition to the gravity we are familiar with, in the downward direction; again, maybe the object is on a table - but let's forget about that for now - he still has to recognize that if he were to pick up an object, it would accelerate partly backwards at $1$ m/s$^2$). Thus, he has a gravity in his frame. He calls the acceleration $\vec{h} = -1 \hat{x}$ and the force $\vec{F}_{\text{h}} = -mh \hat{x}$ where $h = 1$ m/s$^2$. For a sanity check, just as the man standing on the ground, the man in $S'$ has for himself that, $\vec{N} + \vec{F}_h = m\vec{a}$. Where there is some normal force $\vec{N}$. He'd find for himself that $\vec{0} = \vec{0}$. According to $S'$, the force on the object is, $\vec{F}_{\text{net}} = m \vec{a}_{\text{object}}$ or $\vec{F}_{\text{net}} = 4 m \hat{x}$ because he sees the acceleration as you say to be $4$ m/s$^2$. Filling in the forces (as you would, say, if an object is falling with air resistance) $\vec{F}_{\text{net}} = \vec{F}_{\text{something}} + \vec{F}_h$ or $\vec{F}_{\text{something}} - mh \hat{x} = 4m \hat{x}$. Or, $\vec{F}_{\text{something}} = 5m \hat{x}$.
What is the "actual" net force acting on the object? By "actual" I mean, the kind of force that follows Newton's third law.
$5m$ newtons in both cases
(As an aside: Newton's 2nd law works in so called 'non-inertial frames' - as long as you include all gravities. Thus, what we consider inertial frames have only 1 type of gravity, whereas an inertial frame in general can have more than one type of gravity. So if people want to maintain teaching words such as 'inertial' and 'non-inertial' - I don't really understand where they are coming from or what they are trying to achieve - to me it's confusion. Rewording the "coriolis force" and such forces, as "other gravities", I would say then (if I wanted to use the word 'non-inertial'), that all frames are non-inertial because all frames have gravity. The only true inertial frame (if you wanted to maintain that word) is one in which zero gravities are present)