Step 1:
The first step is to copy your installer file from your Application folder to desktop.
Simply, go to your Application folder, right-click the installer file (.app file) and click Copy.
Now create a New Folder on your desktop and paste the .app (installer file) into the New Folder.
Step 2:
Now open Disk Utility from the Launchpad.
Go to Disk Utility > File > New Image > Image from Folder.
Now select the New Folder that we created on the desktop and click Choose.
Name your DMG file and click Save.
The process will take a few seconds and your newly created DMG file will be ready.
The file will be saved on your desktop. See the below snapshot for reference.
SOurce: https://techrechard.com/convert-macos-installer-file-to-dmg/