First you need a patch for the game that will run code from a folder (/SaltySD/SunMoon)
What you can do is first convert the music into a *.bcstm file. To do so, you can download YATA+. Make sure that the music you want to convert is a "wav signed 16 bit pcm" file. Also, after converting it, you need to make sure the music has a size smaller or equal to the file you want to replace.
Then, on your sd card, open the "luma" folder and create a new folder called "titles". Download this zip file with the pre-compiled code.bin files for the latest version of each game (V 1.1):
http://www.mediafire.com/file/ia9u3328q68uu33/V1.1_SM_Patches_for_SaltySD.zip. Inside, you should have 2 folders, one named "Outlines" and another named "No Outlines". Select which one you prefer and copy its contents (both folders have the patches for both games).
After that, just make a folder called "SaltySD" on the root of your sd card, and make a folder named "SunMoon" inside. Then, make a folder named "data" inside of it, and and another folder named "sound" inside of the data folder "data". Then, just drag inside the bcstm file with the name of the music you want to replace. (for example, if you want to change the music for random encounters, you have to name it "bgm_nj_vs_norapoke.dspadpcm.bcstm"). To test it out, you can try this music I used to replace the random encounter music:
http://www.mediafire.com/file/c8q41ushk8jab5o/bgm_nj_vs_norapoke.dspadpcm.bcstm(the music is called "Veorra - Change").
I hope it works for you. If you are having trouble, just ask!
P.S. You must have the latest version of luma3ds for this to work. Just use the luma updater to check for updates.