How can I mount a deck gate against Hardie siding?
I would mount the gate with hinges on the 4x4 post on the right. It is structurally sufficient to support the gate. Make it an in-swing right, gate opens into the porch swinging to the right towards the railing.
Then all you need is 2x4 latch post attached to the side of the house for the latch.
You could attach the latch post with a couple of timber screws. (There is not a lot of lateral forces on the latch post but you could use some construction adhesive to assist the holding power of the screws if you are not into a stud).
Drill holes (three should suffice) in the 2x4 and then set it in place plumb and true, use a pencil through the holes to mark the locations on the siding. Drill pilot holes, just slightly smaller then the shank of the screws. You only want to drill just to the sheathing behind the the siding  to avoid splitting the siding. Use a stop collar or tape on your drill bit to so you only drill about 1/2&quot; to 3/4&quot; or so. (you do not know what is in the cavity of the wall like electrical so you don't want to just drill deep.) Also choose the length of your screw so it will only protrude into the sheathing plus a smidgen.
You do not know where the studs are in the wall and it is unlikely, but possible, that one is exactly where you need it. If you can locate it on a stud it would be best, then you could use longer screws  to go into the stud. You may be able to use a stud finder on the inside wall and then a tape measure to transfer that distance on the outside of the wall and see if it lines up with the 4x4.
Before you install the post with the screws, pump some silicone into the holes so that any moisture that gets behind the post is sealed out.

An alternative if you did not want to penetrate the wall of the house would be to
build a  handrail that would be up against the house but not attached to the house.
It could be two 4x4 posts attached to the risers of the steps and tied together with a solid handrail on top and a 2x6 about a foot under that to provide structural integrity, I.E. minimize racking.