Climbing on a teammate is illegal.
In the NCAA, this is a Class B technical foul. When this occurs, two free throws are awarded to any member of the other team.
From NCAA Men's Basketball 2013-14 and 2014-15 Rules, Rule 10 (Fouls and Penalties), Section 4 (Class B Technical Infractions):
Section 4. CLASS B TECHNICAL INFRACTIONS
Art. 1. A technical foul shall be assessed to a player or a substitute
for the following infractions:
Climbing on or lifting a teammate to secure greater height.
PENALTY: Article 1 and Article 2.a through i. Two free throws shall
be awarded to any member of the offended team. All infractions count
toward ejection but do not count toward the team-foul total or
In the NBA, this is considered an Illegal Assist in Scoring, and results in a loss of the ball.
From Official Rules of the National Basketball Association, Rule 10 (Violations and Penalties), Section XIII (Illegal Assist in Scoring):
Section XIII-Illegal Assist in Scoring
a. A player may not assist
himself to score by using the basket ring or back-board to lift, hold
or raise himself.
b. A player may not assist a teammate to gain height
while attempting to score.
PENALTY: Loss of ball. The ball is awarded
to the opposing team at the free throw line extended.