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, weeks 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 tear up memory foam.
I washed a 24” x 24” x 2” sample of memory foam, just as an experiment, and it was a mess. Most of it came through in tact, but a bunch of it tore into dozens of small pieces. The foam did not fare any better in the dryer; it tore into many pieces there as well. If you have a small spill on your memory foam pillow, try spot cleaning. But to guard your pillow from spills and ensure that it will last for many years, a better solution is to be proactive and get a waterproof memory foam pillow protector.