There are two levels to this:
The “Video Mode” defines the resolution of the timeline. The timeline causes all videos that are dropped onto it to be conformed to the Video Mode’s resolution. So if the timeline/Video Mode is horizontal, the timeline output will always be horizontal. Apparently, your Video Mode is still horizontal rather than vertical.
Then there is the Export > Advanced override. This does not change timeline resolution. It simply rescales the output frame before saving it into the video file. In your case, it takes the horizontal timeline output and resizes it to whatever your override values are. Since the timeline output had black bars baked into it due to being horizontal, the black bars are part of the image that is getting resized to 400x700.
For your purposes, the timeline needs to be a vertical resolution. See this manual entry and note that there are a few vertical presets already built-in. But if you specifically need 400x700, you will have to create a custom Video Mode: