The sport of motorcross racing is about learning skills and techniques, challenging yourself to be a better ride and person and most of all enjoying the race. That's the basis of good sportsmanship.
If you don't win, shake the other person's hand and tell them "Good race". There's no reason to have an attitude if you lost. There will be other races and you will have a chance to hone your skills on your motorcross bike to win another race. If someone used a great move to win or did something on their motorcross bike you haven't seen before, ask them to show you that move. You can learn from people who win the race and become a winner yourself.
If someone else is having an attitude about a loss or something they think unfair happened on the motorcross track, don't get pulled into someone else's negativity. It's really easy to join in harping about not winning or having an attitude. It's far better to be above petty back biting and remember why you got into motorcross in the first place - for the pure joy of riding!
Ride safely when competing. Good sportsmanship is also riding a good motorcross race. Don't cut other motorcross riders off and never do anything endangers yourself or the other riders. No motorcross win is worth anyone, including you, getting hurt.
Motorcross is a great sport and it is also competitive. There is no reason to ever have a bad attitude when you don't win or something goes wrong. Chalk it up as an "off" day and roll with it. Watch the people that win motorcross races and follow their winning techniques. When you win your next race, be gracious to the other motorcross riders and you'll be a shining example of good sportsmanship.