To solve the problem of poor masonry quality of traditional wall‐building robots in an uncertain viscoelastic contact environment while reducing energy consumption, reducing contact forces with the environment, and improving work efficiency and smoothness, a segmented multiobjective trajectory optimization method is proposed based on radial basis function (RBF) and nondominated sorting genetic algorithm II (NSGA‐II). The method divides the motion trajectory into the free motion segment and the masonry segment. In the masonry segment, the compensation variable is introduced at the brick‐stopping position, and the values of design variables are obtained by Latin hypercube sampling. The relationship between the objective functions and the design variables is established by using an RBF substitution model. The optimal design is carried out by the NSGA‐II, and the compromise solution is obtained by using the technique for order preference by similarity to an ideal solution algorithm. On this basis, a multiobjective trajectory optimization method based on seven times nonuniform B‐spline curves is proposed for the free motion segment. According to the performance indicators, such as operation efficiency, trajectory smoothness, and energy consumption, the compromise solution is again sought and obtained. Finally, the proposed trajectory optimization method is compared with the standard gate‐shaped trajectory planning method. The results show that after trajectory optimization, the masonry efficiency of the wall‐building robot is improved by 28.36%, and the energy consumption and trajectory smoothness are reduced by 28.68% and 93.81%, respectively. At the same time, the contact force with the environment is reduced by 12.26%, and the masonry error is reduced from 2.67 to 0.13 mm. These results can contribute to the construction of walls and improve the masonry quality of bricks while considering other performance indicators.