I can create a new geopackage and write a tmp layer to it using code below:
#Create a layer
lyr = processing.run("native:randompointsinextent", {'EXTENT':'376242.90699403384,385761.27711294894,6245699.079987993,6249398.011089481 [EPSG:3006]','POINTS_NUMBER':10,'MIN_DISTANCE':0,'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:3006'),'MAX_ATTEMPTS':200,'OUTPUT':'TEMPORARY_OUTPUT'})['OUTPUT']
newgpkg = r'C:\GIS\data\testdata\newgpkg.gpkg'
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "gpkg"
QgsVectorFileWriter.writeAsVectorFormatV2(lyr, newgpkg, QgsCoordinateTransformContext(), options)
But how can I name the table? Here both the geopackage and the layer is named newgpkg.
(This is just a workaround to create a new geopackage and table using code. So if there is another way of doing that, please let me know)