In a word, “no.” Well actually you can wash it, but then you won't want to use it again. You see, memory foam is made of thousands of tiny polyurethane bubbles all stuck together, and these little bubbles have an open cell structure. That means that the walls of each bubble are full of holes, like a wall in a house with windows and doors.
So when water, or any liquid, gets on a memory foam pillow, it soaks right into all the thousands of little holes in the cell walls. Each cell wall allows water to pass into its cell. The cells fill up, but because of the way water works (a thing called surface tension), the water kind of sticks inside each little cell. It’s nearly impossible to dry. The water will stay inside the cells for days, week’s maybe.
By the time your pillow dries out, stuff will have started to grow inside, and then you won’t want to sleep on it any more. Even if there was no problem with drying a memory foam pillow, they are impractical to wash. A washing machine and dryer will tear up memory foam.