How to animate the render size?
I think the only way to do that is to use a python script to adjust and render each frame.

import bpy

res_landscape = [1920,1080]
res_portrait = [1080,1920]

frame_res = {
    1: res_landscape,
    2: res_landscape,
    3: res_portrait,
    4: res_portrait,
    5: res_landscape,
    }

scn = bpy.context.scene

for f,r in frame_res.items():
    scn.frame_set(f)
    scn.render.resolution_x = r[0]
    scn.render.resolution_y = r[1]
    scn.render.filepath = '//renders/image{:03}.jpg'.format(f)
    bpy.ops.render.render('INVOKE_DEFAULT', write_still=True)