How to join only two objects to create a new object using Python
This will work only if all your objects share the same origin and have their transforms applied. Otherwise you will have to convert them using their transform matrices.
Similar to this answer.
We will use itertoolsand itertools.combinations to generate the wanted combinations.
Reference

Then use the bmesh module to concatenate the meshes. (Very important that all transforms be applied and origin at 0,0,0 !)
import bpy
import bmesh
import itertools

objects = bpy.context.selected_objects # Replace with your objects
objects_combinations = itertools.combinations(objects, 2)

for perm in enumerate(objects_combinations):
    this_perm = perm[1]
    new_mesh = bpy.data.meshes.new(this_perm[0].name + this_perm[1].name)
    
    new_bm = bmesh.new()
    new_bm.from_mesh(this_perm[0].data)
    new_bm.from_mesh(this_perm[1].data)
    new_bm.to_mesh(new_mesh)

    new_obj = bpy.data.objects.new(this_perm[0].name + this_perm[1].name, new_mesh)
    
    bpy.context.scene.collection.objects.link(new_obj)

    new_bm.free()

Result :