Is the idea of "boarding university" still a formal policy? In the past, most education centers were boarding schools in which students live full time. Still there are boarding school at high school or college level. However, for universities, students just tend to attend the class and leave the campus. Even, dormitories are just like rental projects rather than keeping the students to live in the campus.

Old-fashioned universities like Cambridge still have the so-called colleges which are responsible for student life (to live in the academic community). In this classic model, the university is investing in colleges to build an academic community outside formal education, which is conducted by technical departments.

Is it a formal policy for modern universities to keep students within the campus beside the formal education? OR they prefer if the students attend classes and leave the campus?

The reason that I ask this question is that social activities are conducted by student clubs. If students do not join clubs or somehow live in the campus, it is not responsibility of the university administration (and they normally do not care). In classical universities like Cambridge, keeping the colleges active is still responsibility of the university administration.
In the United States, it tends to depend strongly on the particular university and the population that it aims to serve.  In general, the more local and "non-traditional" that students are expected to be, the less that a university will feel obligated to assist in the arrangement of housing and board.

Thus, for example, a place like Williams College, where the students are mostly "traditional" undergraduates coming from far away to a small isolated town in the mountains, expects to house, board, and provide a full campus life for essentially all of its students.  

At the opposite end of the spectrum there are places like Suffolk University, which is in the middle of a big city (Boston) and historically focused strongly on professional postgraduate education and on students enhancing their education later in life.  Suffolk doesn't even have a campus per se---it just has about a dozen buildings scattered around the center of Boston, and until quite recently did not have any dormitories at all.

Across the whole spectrum, most administrations will consider it their responsibility to provide a rich intellectual environment for students both inside and outside of the classroom, e.g., by supporting student groups.  The degree to which this happens "on campus" and with direct university investment varies greatly depending on circumstance.  No university in America, however, will attempt to confine students to a campus---some merely recognize that geography makes it more difficult for their students to leave.