This is in a song I've heard. Is it grammatically correct?
Technically this is grammatically correct, however it is not common for someone to use the first person for both the subject and the direct object of a sentence, as it comes across as somewhat redundant.
"Now I lay down to sleep" has the same meaning and is a more conventional way of saying this. Although I'm sure the choice to use "Now I lay me down to sleep" was done for poetic reasons and there's nothing wrong with that.