I need to create a layout in which the vertices of the map in the layout coincide with the vertices of a rectangle of a grid that is oriented differently from the map on which it is overlayed: what can be the correct way to do it?
If by orientation you mean the map rotation you can use the 'Oriented minimum bounding box' tool on your polygon layer with the CRS of your basemap. It will create a field called 'angle'. You can then insert this angle using a custom expression in the map item properties in the 'map rotation' field. Since it is your atlas feature(probably) you can grab it by using the expression:
"angle". You might have to use
replace("angle",',','.') since map rotation only uses . as a delimiter.