What you're saying in your code is the following:
"If the up key or the right key is pressed, play the animation. Then in the following bit, if neither the right nor the left key are pressed play idle."
This means that if you press only the up or down keys the statement for putting it on idle is true. There's a couple ways to fix this. You can either put an 'else if up or down isn't pressed' instead of the else you have right now before putting it on idle. Or you can move the block of code involving the up and down key below the left and right key bit. Be weary though, because you might be resetting your animation every frame when doing this (left and right aren't being pressed, so put on idle, then it sees up or down is pressed so it puts it on walking). Therefore the latter will only work when it's a single frame 'animation'.
Be sure to mess around a bit on your own, because there's more than the two ways I mentioned to fix this.