Yes, but...
Splices must be in an electrical box and must be accessible. There are various ways this can be done.
Never splice wires without a box and never bury splices in a wall or inaccessible area, even if they are in a box! If there is ever a problem in the splice you want to be able to smell it before it becomes a fire, you want to be able to get to it to do something about it and if a connection ever overheats enough to start burning you want it to be contained in a closed box so it can't get enough air to support combustion.
Having a problem in a buried splice that was made by a building's previous owner creates at least an expensive headache for a new owner who doesn't know where to find the splice.